How To

Not returned Sub variable trick

3

SP4CEBAR 2022-12-22 09:06 (Edited)

If you wrap each value that should not change by a subprogram in parentheses, then it'll not be returned: for example "CALL TEST((A))", A is not returned, it's value won't change

A=1
CALL TEST((A))
PRINT A

SUB TEST(A)
  A=2
END SUB

It prints out "A=1"


Timo 2022-12-22 09:44

That’s because you don’t pass the variable anymore, but an already calculated value… although there is not much to calculate with only one value ;)


Timo 2022-12-22 09:46

An extra pair of parenthesis means: calculate the content first and return the result.


SP4CEBAR 2022-12-22 11:25

I already assumed so, thanks for the confirmation
I'm definitely going to use this instead of
B=A
CALL TEST(B)
when I don't want "A" to be modified


nathanielbabiak 2022-12-22 12:38

This is a good trick!


was8bit 2022-12-22 15:48

Pretty cool little trick ;)


GAMELEGEND 2022-12-22 16:07

Interesting


Log in to reply.