I've written about 8 or 9 pages of script and it started acting funny on me. Are there symbol table or other limitations I should know about?
Henry
What are the limitations on Scripting?
Re: What are the limitations on Scripting?
hharris wrote:I've written about 8 or 9 pages of script and it started acting funny on me. Are there symbol table or other limitations I should know about?
Henry
Not that I know of. In what way is it acting funny?
- Hank
-
Topic authorhharris
- Posts: 79
- Joined: 23.02.2006
- With us: 18 years 9 months
- Location: Pasadena, CA 91104
RE:What are the limitations on Scripting?
Hank,
I solved this problem by doing something I should have done in the beginning. I wrote a few test scripts and studied how parameters are passed, the rules about using local variables etc. Once I understood what celx expects it solved most of my problems. I suppose there is a formal description somewhere, but I couldn't find it.
One thing I never tested, though. Is it possible to pass a value out through the argument list, or are you limited to the "list" return? Probably not, I would guess, since I didn't see anything like the address of a variable.
Henry
I solved this problem by doing something I should have done in the beginning. I wrote a few test scripts and studied how parameters are passed, the rules about using local variables etc. Once I understood what celx expects it solved most of my problems. I suppose there is a formal description somewhere, but I couldn't find it.
One thing I never tested, though. Is it possible to pass a value out through the argument list, or are you limited to the "list" return? Probably not, I would guess, since I didn't see anything like the address of a variable.
Henry
-
- Posts: 164
- Joined: 18.03.2004
- Age: 63
- With us: 20 years 8 months
- Location: Victoria, BC Canada
Re: RE:What are the limitations on Scripting?
hharris wrote:One thing I never tested, though. Is it possible to pass a value out through the argument list, or are you limited to the "list" return? Probably not, I would guess, since I didn't see anything like the address of a variable.
If a function is called with a list as the parameter then, even though the list is treated as pass-by-value, the elements of the list are pass-by-reference. e.g.
Code: Select all
function attemptA(parm1)
celestia:flash("attemptA called with "..parm1.x..","..parm1.y,5);wait(5)
parm1 = {x=100,y=100}
celestia:flash("attemptA set parm1 to "..parm1.x..","..parm1.y,5);wait(5)
return
end
function attemptB(parm1)
celestia:flash("attemptB called with "..parm1.x..","..parm1.y,5);wait(5)
parm1.x=100
parm1.y=100
celestia:flash("attemptB set parm1 to "..parm1.x..","..parm1.y,5);wait(5)
return
end
a = {x=1,y=2}
celestia:flash("a.x="..a.x.."\na.y="..a.y.."\ncalling attemptA(a)",5);wait(5)
attemptA(a)
celestia:flash("a.x="..a.x.."\na.y="..a.y.."\ncalling attemptB(a)",5);wait(5)
attemptB(a)
celestia:flash("a.x="..a.x.."\na.y="..a.y,5)
The function attemptA tries to alter the actual list. This will only succeed locally within the function. When we return to main code, the list is unaltered.
The function attemptB alters the contents of the list. This works globally and upon exiting the main code we can see the contents of the list are altered.
Additionally, a function can return more than one value, so you are not limited to using a list to return values.
Code: Select all
function test()
return 5,"hello world",15
end
x,y,z = test()
celestia:flash(y.."\nx="..x,z)
Hope that helps.
Clive Pottinger
Victoria, BC Canada
Victoria, BC Canada