Argument passing not working in console 

Hey guys,
you might already know this, but passing arguments to a function in the console doesn't seem to work.

function test(xxx){

Gives this result

VMachine::getOperand - uninitialized value (unknown location)
Script::Message - undefined

Maciej Komosinski's picture

Please tell which console you are using (GUI or CLI), and what you paste in individual lines.

If you just paste that code directly into the console in the windows GUI it won't work.
But if you paste that function into, say, frams.ini and then type
on the CLI it works just fine.

Obviously not a big deal, most people probably aren't using the GUI console to test complete functions...

Maciej Komosinski's picture

Defining functions cannot be done in console mode, no matter if arguments are used or not... sorry.

Actually your program handles functions in console just fine!
Copy and paste this into the gui console:

function test(){
var xxx=3;

The output is:

Script::Message - 3

so the functions work, just not arguments.

Szymon Ulatowski's picture

The truth is even more convoluted :)

The following code:
function test() {var xxx=3; Simulator.print(xxx);} test();

does not actually call the function test() - the last statement is never executed (you can omit test(); or call it twice test(); test(); and it won't change anything).
But it works - it prints "3"!

It works because defining a function is like writing a normal code, the command line just executes everything in the function body and then the closing } works as a return statement so the execution ends and never reaches "test();".

The next variant shows the effect more clearly (it calls test() and then executes the function body again - you will see two 3's)
test(); function test() {var xxx=3; Simulator.print(xxx);}

So now we see what happens in the original example (with arguments) - the body of the function is executed but it was not really called so its arguments are not initialized and this is detected by the runtime.

Knowing all this, the "proper" way of abusing the CLI would be:

test(123); test(321); return; function test(xxx) {Simulator.print(xxx);}

(note the return; statement before "function". Without it the function body would be executed for the third time, giving an error message about uninitialized value)

Ha! wow.