Page 1 of 1

What are the limitations on Scripting?

Posted: 01.03.2006, 02:55
by hharris
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

Re: What are the limitations on Scripting?

Posted: 01.03.2006, 05:54
by hank
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

RE:What are the limitations on Scripting?

Posted: 01.03.2006, 08:01
by hharris
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

Re: RE:What are the limitations on Scripting?

Posted: 01.03.2006, 12:48
by cpotting
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.