Function Weirdness
|
Tad Jensen
Script Junkie
Join date: 29 May 2004
Posts: 24
|
11-19-2004 09:42
is there a limitation to how much code / type of code you place inside braces inside a user defined function? i was playing around with a script the other day using the particle system and inside the function i was cycling through some number of iterations to spawn the particle system multiple times so the function looked something like this... myfunction() { integer x; for (x = 0; x < 2; x++) { if (x == 0) { do some code here; } else { do like 3 lines of variable assignments here; do the particle system code here; } } }
i had plenty of other code in the script... but this something very odd happened... this compiled fine a few times and was executing my script, etc and was still making changes to code, etc other places in the script... all of a sudden I started getting a syntax error in like the last line in my llParticleSystem function call... but i had not even touched any code in my user defined function. first, i thought the script might have gotten into some state of error and was just throwing the syntax error for the heck of it so i created a new script in the object and pasted my code in there... still got the syntax error. second, i started playing around with the general area that it gave me the syntax error... i removed like one of the options (list items) in llParticleSystem and it compiled... so im like WTF... i readded the one i removed and it gave me the syntax error again... well i removed a different option in llParticleSystem this time and it compiled again... WEIRD right? so then i started playing some more because im like that doesn't make sense... i removed the entire piece in my else { } part of my function and it compiled... put it back, didn't compile so i was like ok let me try this.... myfunction() { integer x; for (x = 0; x < 2; x++) { do like 3 lines of variable assignments here; do the particle system code here; } }
this compiled? so its not the particle system code... finally i just gave up trying to understand the weirdness and created another function and only put my llParticleSystem code in it... and the final result was this... callmyparticlesystemfunction(acceptvars) { do like 3 lines of variable assignments here; do the particle system code here; }
myfunction() { integer x; for (x = 0; x < 2; x++) { if (x == 0) { do some code here; } else { callmyparticlesystemfunction(passvars); } } }
this worked completely fine and haven't had trouble since... any ideas? sorry if my explanation is weird... not good at explaining things... Tad Jensen
|
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
|
11-19-2004 16:33
Haven't heard of that before... i'd say submit a bug report. A function is only limited to how much memory the script has -- so functions can contain much more lines and information then you have there... so your explanation of the error smells like a bug... but if you're getting a syntax error with that code -- dunno. It looks fine to me syntax-wise.
--Water
_____________________
From: Philip Linden For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
|
Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
|
11-19-2004 20:44
it does sound like a bug.
but if you want someone to have a look at your actual code to get a better idea, then you can send it to me, and i promise not to copy it or anything. Or try asking a Live Helper (i used to be one, and would happily do it for you, so i'm sure they will).
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-20-2004 00:18
yes there is a limit to the complexity of code. I've never actualy calculated what it is (too damn lazy, since hitting it is rare). The specific limit is tied to the complexity of code that exists in an If-Else-If block. More accurately a very large If-Else-If-Else-If-Else-If-Else-If-Else-If-Else-If-Else with nested If-Else-If's in them. think the limit might be 15 nested or chained control logic structures. I wish we had case statements. I had this problem with... /15/79/15853/1.html
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Dan Medici
Registered User
Join date: 25 Jan 2004
Posts: 132
|
11-22-2004 16:59
From: Strife Onizuka I wish we had case statements.
(me being a former C programmer) Ditto.
|
Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
|
11-22-2004 18:28
yes case statements and arrays are Neeeeeeeeeeded in SL. I have been learning C++ after scripting in Sl for months, and have now realised that all of my large projects would have been ALOT easier with both of these, and no doubt use much less server resources.
|
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
|
11-22-2004 19:37
Well, personally I'm putting my bets on a missing "
Azelda
|
Tad Jensen
Script Junkie
Join date: 29 May 2004
Posts: 24
|
11-23-2004 07:06
From: Azelda Garcia Well, personally I'm putting my bets on a missing "
Azelda wish it were that simple  there wasn't anything wrong with the syntax, that was the point... it was the positioning of the code... i could put the same code that threw the syntax error in a different BLOCK and it worked fine...
|
Apotheus Silverman
I write code.
Join date: 17 Nov 2003
Posts: 416
|
11-23-2004 09:47
I also have run across these odd-seeming errors numerous times in the past. They universally ended up being due to the exact way some statement was represented, such as forgetting a space on one side of an operator, or needing to put a type conversion inside parentheses when it technically should not have been necessary. LSL has a few of those undocumented features. 
|
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
|
11-23-2004 13:17
I'm betting it was a typographical error. Once that the compiler wasn't giving you a good pointer to.
_____________________
~ Tiger Crossing ~ (Nonsanity)
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-27-2004 19:17
This script (shown below) won't compile because the compiler runs out of memory. If anyone can point out a typo (constitutes changing 3 or fewer characters) that will result in this code compiling & running I will pay 1000L$ to that person (this offer is only valid until the next update, code must compile under normal conditions, must be reproducable, LL employies, friends, relatives, and Alts are prohibited from participating).This example illustrates where a "case" statement would be useful. It's not a good example but it is none the less an example. Considering how difficult it can be to determin in large blocks of code if there is a syntax mistake; and how easy it is to count statements, i would recommend starting with counting statements. Nested statements eat more memory then chained statements. I would like to see a server dedicated to compiling scripts, that has an open interface so scripts can be compiled on it outside of SL as well. n() { llSay(0,"hi"); }
m() { integer d; while(d<50) { ++d; if(d==1) { n(); } else if(d==2) { n(); } else if(d==3) { n(); } else if(d==4) { n(); } else if(d==5) { n(); } else if(d==6) { n(); } else if(d==7) { n(); } else if(d==8) { n(); } else if(d==9) { n(); } else if(d==10) { n(); } else if(d==11) { n(); } else if(d==12) { n(); } else if(d==14) { n(); } else if(d==15) { n(); } else if(d==16) { n(); } else if(d==17) { n(); } else if(d==18) { n(); } else if(d==19) { n(); } else if(d==20) { n(); } else if(d==21) { n(); } else if(d==22) { n(); } else if(d==23) { n(); } else if(d==24) { n(); } else if(d==25) { n(); } else if(d==26) { n(); } else if(d==27) { n(); } else if(d==28) { n(); } else if(d==29) { n(); } else if(d==30) { n(); } else if(d==31) { n(); } else if(d==32) { n(); } else if(d==33) { n(); } else if(d==34) { n(); } else if(d==35) { n(); } else if(d==36) { n(); } else if(d==37) { n(); } else if(d==38) { n(); } else if(d==39) { n(); } else if(d==41) { n(); } else if(d==42) { n(); } else if(d==43) { n(); } else if(d==44) { n(); } else if(d==45) { n(); } else if(d==46) { n(); } else if(d==47) { n(); } else if(d==48) { n(); } else if(d==49) { n(); } } }
default { state_entry() { m(); } }
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
|
11-27-2004 22:54
That script won't compile because that chain of conditionals is too long, no? The maximum is 23 'else's, per the wiki...
_____________________
- Making everyone's day just a little more surreal -
Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
|
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
|
11-27-2004 22:59
Yeah, that's not at all the same code as what Tad is presenting.
|
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
|
11-27-2004 23:01
That said, I'm always game for L$1000. Here's the above code in a compilable format, with just 2 characters added: n() { llSay(0,"hi"); }
m() { integer d; while(d<50) { ++d; if(d==1) { n(); } else if(d==2) { n(); } else if(d==3) { n(); } else if(d==4) { n(); } else if(d==5) { n(); } else if(d==6) { n(); } else if(d==7) { n(); } else if(d==8) { n(); } else if(d==9) { n(); } else if(d==10) { n(); } else if(d==11) { n(); } else if(d==12) { n(); } else if(d==14) { n(); } else if(d==15) { n(); } else if(d==16) { n(); } else if(d==17) { n(); } else if(d==18) { n(); } else if(d==19) { n(); } else if(d==20) { n(); } else if(d==21) { n(); } else if(d==22) { n(); } else; if(d==23) { n(); } else if(d==24) { n(); } else if(d==25) { n(); } else if(d==26) { n(); } else if(d==27) { n(); } else if(d==28) { n(); } else if(d==29) { n(); } else if(d==30) { n(); } else if(d==31) { n(); } else if(d==32) { n(); } else if(d==33) { n(); } else if(d==34) { n(); } else if(d==35) { n(); } else if(d==36) { n(); } else if(d==37) { n(); } else if(d==38) { n(); } else if(d==39) { n(); } else if(d==41) { n(); } else if(d==42) { n(); } else if(d==43) { n(); } else if(d==44) { n(); } else if(d==45) { n(); } else; if(d==46) { n(); } else if(d==47) { n(); } else if(d==48) { n(); } else if(d==49) { n(); } } }
default { state_entry() { m(); } }
Azelda
|
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
|
11-27-2004 23:14
For the record, Strife has honoured his wager. Wheee!
Azelda
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-27-2004 23:20
$&#*#$ i forgot an else at the bottom *feels very poor* here's how you would write that code with a case statement n() { llSay(0,"hi"); }
m() { integer d; while(d<50) { ++d; switch(d) { case 1: ; case 2: ; case 3: ; case 4: ; case 5: ; case 6: ; case 7: ; case 8: ; case 9: ; case 10: ; case 11: ; case 12: ; case 13: ; case 14: ; case 15: ; case 16: ; case 17: ; case 18: ; case 19: ; case 20: ; case 21: ; case 22: ; case 23: ; case 24: ; case 25: ; case 26: ; case 27: ; case 28: ; case 29: ; case 30: ; case 31: ; case 32: ; case 33: ; case 34: ; case 35: ; case 36: ; case 37: ; case 38: ; case 39: ; case 40: ; case 41: ; case 42: ; case 43: ; case 44: ; case 45: ; case 46: ; case 47: ; case 48: ; case 49: n(); } } }
default { state_entry() { m(); } }
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
11-28-2004 00:48
From: Tad Jensen is there a limitation to how much code / type of code you place inside braces inside a user defined function?
i was playing around with a script the other day using the particle system and inside the function i was cycling through some number of iterations to spawn the particle system multiple times so the function looked something like this... The only things that should make the compiler spit an error at you due to length are when a script's bytecode is over 16k (I think), when you have a list literal that has too many elements (about 20 I think) or if you have a very very long conditional chain (too many else-ifs). Considering that you declare particle system parameters, it might be the literal list-length limit that's bothering you. If that's true, use two (or more) list literals then combine them together before passing them to the llParticleSystem call. ==Chris
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
11-28-2004 10:50
From: Strife Onizuka n() { llSay(0,"hi"); }
m() { integer d; while(d<50) { ++d; switch(d) { case 1: ; case 2: ; case 3: ; case 4: ; case 5: ; case 6: ; case 7: ; case 8: ; case 9: ; case 10: ; case 11: ; case 12: ; case 13: ; case 14: ; case 15: ; case 16: ; case 17: ; case 18: ; case 19: ; case 20: ; case 21: ; case 22: ; case 23: ; case 24: ; case 25: ; case 26: ; case 27: ; case 28: ; case 29: ; case 30: ; case 31: ; case 32: ; case 33: ; case 34: ; case 35: ; case 36: ; case 37: ; case 38: ; case 39: ; case 40: ; case 41: ; case 42: ; case 43: ; case 44: ; case 45: ; case 46: ; case 47: ; case 48: ; case 49: n(); } } }
default { state_entry() { m(); } }
I dont understand why anyone would code like that. Why not just use if (d <= 49 && d >=1) n(); Three conditional operations versus 48, or even better: integer d; for (d = 1; d <= 49; ++d) n(); ==Chris
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-28-2004 15:50
i think i said it was a *bad* example.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Tad Jensen
Script Junkie
Join date: 29 May 2004
Posts: 24
|
11-29-2004 10:53
hey guys, nice thread... if i can recreate the problem i was having when I get home I will post the source code in here trimmed down... pretty sure it wasn't regarding any of nested block limitations... didn't think saving my broken code would have been smart but i guess for others to make judgements on something without seeing the code would be hard, i should have known better,,, rofl ... sorry 
|