|
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
|
11-22-2007 07:46
have having trouble geting my text speed control hud to work right, it dosent update as it should, cant figure out what i did wrong
string text; vector velocity; string speed;
default { state_entry() { llSetTimerEvent(.1); } timer() { velocity = llGetVel(); speed = (string)llVecMag(velocity); speed = llGetSubString(speed, 0, llSubStringIndex(speed, ".") + 3); text += " Speed: " +speed+ " m/s"; llSetText(text +"", <0.25, 0.25, 1.0>, 1.0); } }
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
11-22-2007 08:32
From: Mrc Homewood text += " Speed: " +speed+ " m/s"; Since text is a global variable, " Speed: " +speed+ " m/s" is being appended to it each time through the timer loop. You want to just assign (=), not concatenate and assign (+=). A few other things: From: someone speed = llGetSubString(speed, 0, llSubStringIndex(speed, "."  + 3); If you only want 3 digits after the decimal, it would be faster to use llGetSubString( speed, 0, -4 ) Since a float cast to a string always includes 6 digits after the decimal. In fact, the whole operation could be done in a single line inside timer, with no global variables necessary: llSetText( llGetSubString( (string)llVecMag( llGetVel() ), 0, -4 ), <0.25, 0.25, 1.0>, 1.0 );
|
|
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
|
11-22-2007 09:32
ok it works but now im trying to get it into messuing knots this is what i have, i get a error at the end of the line
speed = (integer)(llVecMag(velocity) * 1.94384449 + 0.5);
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
11-22-2007 10:00
If speed is still a string variable, you need to cast to a string before assigning.
|