Difference between revisions of "NumPad"
Jump to navigation
Jump to search
m (→Main Script: the left and right empty sides empty had a off by 1 error ^_^) |
(Un-broke the code formatting) |
||
(One intermediate revision by one other user not shown) | |||
Line 32: | Line 32: | ||
==Main Script== | ==Main Script== | ||
< | <source lang="lsl2"> | ||
/ | //////////////////////////////////////////////////// | ||
// NumPad | |||
// ---------------- | |||
// Version: 1.0 | |||
// By: Madpeter Zond | |||
// About: A 1 texture 10 digit number display | |||
// great for a score output. | |||
//////////////////////////////////////////////////// | |||
string texture = "31f72af5-dee3-72f5-3981-bde21bf85e9c"; | string texture = "31f72af5-dee3-72f5-3981-bde21bf85e9c"; | ||
integer render_to_prim_number = LINK_THIS; | integer render_to_prim_number = LINK_THIS; | ||
Line 59: | Line 60: | ||
render(string output) | render(string output) | ||
{ | { | ||
while(llStringLength(output) < 10) { output = ""+output+" "; } | while(llStringLength(output) <= 10) { output = ""+output+" "; } | ||
list renderrules = []; | list renderrules = []; | ||
integer loop = 0; | integer loop = 0; | ||
Line 65: | Line 66: | ||
{ | { | ||
string part = llGetSubString(output,(2*loop),(2*loop)+1); | string part = llGetSubString(output,(2*loop),(2*loop)+1); | ||
if(part == " ") | if(part == " ") | ||
{ | { | ||
// empty | // empty | ||
Line 74: | Line 75: | ||
integer Y_offset = (integer)llGetSubString(part,0,0); | integer Y_offset = (integer)llGetSubString(part,0,0); | ||
integer X_offset = (integer)llGetSubString(part,1,1); | integer X_offset = (integer)llGetSubString(part,1,1); | ||
if(llGetSubString(part,0,0) == " ") | if(llGetSubString(part,0,0) == " ") Y_offset = 10; // left side empty | ||
else if(llGetSubString(part,1,1) == " ") Y_offset = 11; // right side empty | else if(llGetSubString(part,1,1) == " ") | ||
{ | |||
Y_offset = 11; // right side empty | |||
X_offset = (integer)llGetSubString(part,0,0); | |||
} | |||
vector start = llList2Vector(grid_offset_starts,loop); | vector start = llList2Vector(grid_offset_starts,loop); | ||
start = <fix(start.x + (0.1 * X_offset)),fix(start.y + (-0.083333333 * Y_offset)),0>; | start = <fix(start.x + (0.1 * X_offset)),fix(start.y + (-0.083333333 * Y_offset)),0>; | ||
renderrules = renderrules + [PRIM_TEXTURE,llList2Integer(faces,loop),texture,repeats_config+llList2Vector(repeats_corrections,loop),start,0,PRIM_COLOR,llList2Integer(faces,loop),render_color,1,PRIM_GLOW,llList2Integer(faces,loop),glow_amount]; | renderrules = renderrules + [PRIM_TEXTURE,llList2Integer(faces,loop),texture,repeats_config+llList2Vector(repeats_corrections,loop),start,0,PRIM_COLOR,llList2Integer(faces,loop),render_color,1,PRIM_GLOW,llList2Integer(faces,loop),glow_amount]; | ||
} | } | ||
loop++; | loop++; | ||
} | } | ||
llSetLinkPrimitiveParamsFast(render_to_prim_number,renderrules); | llSetLinkPrimitiveParamsFast(render_to_prim_number,renderrules); | ||
} | } | ||
default | default | ||
Line 92: | Line 96: | ||
} | } | ||
} | } | ||
</ | </source> | ||
==Texture layout== | ==Texture layout== |
Latest revision as of 21:56, 4 April 2015
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Scripting tools to allow display of text on a prim: XyText 1.5 , XyzzyText, XyyyyzText, XyText-UTF8, XyzzyText-UTF8, ZZText, VariText
NumPad is a variant of the text on a prim but with some changes
- 1 texture vs 5 textures needed for XyText 1.5 'to render numbers'
- Numbers and spaces only.
- About 73 lines of code.
Copyright & Licensing
- Madpeter Zond hereby releases his contributions to this under the MIT license. [Starting texture and Starting code]
NumPad 10digits
Quickstart:
* Take a copy of the 10 char prim setup from [[XyText 1.5]] and setup a prim * After running the code create a new script and copy the NumPad code to it.
Usage:
* Set render_to_prim_number to the number of the prim you wish to render to, * if you dont know the number you can put the script inside of the prim you want * and not change this.
Main Script
////////////////////////////////////////////////////
// NumPad
// ----------------
// Version: 1.0
// By: Madpeter Zond
// About: A 1 texture 10 digit number display
// great for a score output.
////////////////////////////////////////////////////
string texture = "31f72af5-dee3-72f5-3981-bde21bf85e9c";
integer render_to_prim_number = LINK_THIS;
vector render_color = <1,1,1>;
float glow_amount = 0.00;
// please dont change this unless you want to break something ^_^
list faces = [3,7,4,6,1];
list grid_offset_starts = [<-0.38941,-0.54747,0> ,<-0.44939,-0.54750,0>, <0.01800,0.45256,0>,<-0.44939,-0.54750,0>,<-0.50941,-0.54747,0>];
list repeats_corrections = [<0.1,0,0>,<0,0,0>,<-1.35,0,0>,<0,0,0>,<0.1,0,0>];
vector repeats_config = <0.1,0.083333,0>;
float fix(float input) // render blocking fix [haxy]
{
if(input > 1.0) input -= 1.0;
else if(input < -1.0) input += 1.0;
return input;
}
render(string output)
{
while(llStringLength(output) <= 10) { output = ""+output+" "; }
list renderrules = [];
integer loop = 0;
while(loop < 5)
{
string part = llGetSubString(output,(2*loop),(2*loop)+1);
if(part == " ")
{
// empty
renderrules = renderrules + [PRIM_COLOR,llList2Integer(faces,loop),<1,1,1>,0,PRIM_GLOW,llList2Integer(faces,loop),0];
}
else
{
integer Y_offset = (integer)llGetSubString(part,0,0);
integer X_offset = (integer)llGetSubString(part,1,1);
if(llGetSubString(part,0,0) == " ") Y_offset = 10; // left side empty
else if(llGetSubString(part,1,1) == " ")
{
Y_offset = 11; // right side empty
X_offset = (integer)llGetSubString(part,0,0);
}
vector start = llList2Vector(grid_offset_starts,loop);
start = <fix(start.x + (0.1 * X_offset)),fix(start.y + (-0.083333333 * Y_offset)),0>;
renderrules = renderrules + [PRIM_TEXTURE,llList2Integer(faces,loop),texture,repeats_config+llList2Vector(repeats_corrections,loop),start,0,PRIM_COLOR,llList2Integer(faces,loop),render_color,1,PRIM_GLOW,llList2Integer(faces,loop),glow_amount];
}
loop++;
}
llSetLinkPrimitiveParamsFast(render_to_prim_number,renderrules);
}
default
{
state_entry()
{
render("1234567890");
}
}
Texture layout
the texture is setup in a 10x12 format as follows.
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 0_ 1_ 2_ 3_ 4_ 5_ 6_ 7_ 8_ 9_
Improvements
there are some improvements that could be made
1: Change the texture format to 11x11 to improve the quality of the numbers.
2: Change the while loop to a for loop if that saves memory.
3: Change the way it builds rules if a way is found that saves script memory.