|
Rook Inventor
Registered User
Join date: 11 Mar 2009
Posts: 22
|
03-16-2009 20:50
OK, this has been driving me insane for 2 days now. I'm teaching myself scripting and I ran into a strange problem that I can't solve. I have a global variable (groll) that I can't do anything with. I assign it an integer. I can verify the integer has been assigned by having it llSay it back to me. But I try using it in a loop and the loop is ignored. I try using it in an if statement and it does not evaluate true or false. It is just ignored. Anybody seen anything like this? Your help would be greatly appreciated. Here's the script. Its supposed to roll a number of dice based on the input of the user. (User clicks on a die object on a HUD) The script is not complete yet and full of my debug code. If this is familiar to you, please help. I'm a rookie. Thanks! integer groll; list dieAccum; default { link_message(integer sender_num, integer num, string str, key id) { if (str == "Roll" { groll = (sender_num - 15); llSay(0, (string)groll); state rolling; } } } state rolling { state_entry(){ integer r; integer num = groll; for (r = 0; r < num; r++) { integer dieRoll = (integer) llFrand (6.0)+1; dieAccum = dieAccum + dieRoll; llSay(0, (string)r); llSay(0, "rolling"  ; } float dieTotal = llListStatistics(6, dieAccum); (integer) dieTotal; string roll = "test"; //integer num = groll; llSay(0, (string)dieTotal); if (num == 1) roll = " die has "; else if (num > 1) roll = " dice have "; //llsay(0, roll); string respond = (string) num + roll + " been cast. "; llSay(0, respond); groll = 0; respond = ""; state default; } }
|
|
Viktoria Dovgal
…
Join date: 29 Jul 2007
Posts: 3,593
|
03-16-2009 22:32
This looks like it could be your problem:
groll = (sender_num - 15);
In the other state you assign groll's value to num, and then check if num is either 1 or >1 . If I force those to happen up in the groll assignment, all seems to be well with the plural/singular thing. But if groll is less than 1, the if never happens and I get garbage results. Is there something funny with your link numbers that the script isn't prepared to handle?
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-17-2009 00:19
yup if (sender_id - 15) < 1, your for loop will never run, and neither will the if conditions following it
other problems I see
integer num = groll; //-- num never changes, so just replace all instances with groll and save yourself a variable.
dieAccum = dieAccum + dieRoll; //-- dieRoll really should be cast to (list)
llSay(0, (string)r); //-- probably should be (r + 1), unless you meant your dice to start numbering throws at 0
(integer) dieTotal; //-- doe nothing beause it's not saved back to a variable, did you mean (dieTotal = (integer)dieTotal)
dieAccum = dieAccum + dieRoll; //-- dieAccum will continue to grow with every roll since it is never cleared. eventually it'll crash the script, in the short term it'll accumulate all successive sets of rolls and blow, making on the first set accurate. (unless you intended that, in which case you still need to cap the list length like so: dieAccum = llList2List( dieAccum, 1, 99 ) + (list)dieRoll; //-- last 100 individual rolls )
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Rook Inventor
Registered User
Join date: 11 Mar 2009
Posts: 22
|
03-17-2009 15:35
Thank you guys! Viktoria you hit it. I don't know why I didn't see it myself. It was a math problem, where I thought it had something to do with states or scope. Sometimes something simple needs to be looked at simply I guess. Thanks!
|