is it safe to use variables not sent to func
Posted: Wed Dec 21, 2022 11:39 am
I accidentally did some bad code today by not having sent necessary information to the Function, but used those variables from outside the function, and it worked.
here an example:
Normally I would send that n as one of the arguments to "myfunc", but this time I didnt.
As I was wondering about this, this could actually be somewhat handy way to make code cleaner in some cases, like:
instead of:
But is this a safe way to do this otherwise, except that n cant be Local, which in itself can cause problems?
here an example:
Code: Select all
Function myfunc()
DebugPrint(n)
EndFunction
For n = 1 To 3
myfunc()
Next
As I was wondering about this, this could actually be somewhat handy way to make code cleaner in some cases, like:
Code: Select all
for n = 1 to 100
DrawEnemy()
next
Code: Select all
for n=1 to 100
DrawEnemy(Enemy[n].x, Enemy[n].y, Enemy[n].Weapon, Enemy[n].status,Enemy[n].whatevermore)
next