06-16-2012, 11:02 AM
i'll merge these in later, just posting coz i worked out some magical stuff.
you can define functions like the following example, and you can have function pointers:
in functions, you cannot access global variables, so anything within a function has to be passed in as a parameter (maybe you can define new variables in functions, untested). so if you want to manipulate globals, you have to do it in the global code space (i.e. not in a function).
Azriel~
you can define functions like the following example, and you can have function pointers:
C-Code:
def func1() { return true; } def func2() { return false; } var v1 = func1(); var v2 = func2(); var f3 = func1; var f4 = func2; var v3 = f3(); var v4 = f4(); clr(); print("v1: ${v1}"); // true print("v2: ${v2}"); // false print("v3: ${v3}"); // true print("v4: ${v4}"); // false |
in functions, you cannot access global variables, so anything within a function has to be passed in as a parameter (maybe you can define new variables in functions, untested). so if you want to manipulate globals, you have to do it in the global code space (i.e. not in a function).
C-Code:
var xRange = self_x - target_x; var yRange = self_y - target_y; var zRange = self_z - target_z; // function pointers var approachTargetX; var departTargetX; var approachTargetZ; var departTargetZ; // setup x commands if (xRange <= 0) { approachTargetX = right; departTargetX = left; } else { approachTargetX = left; departTargetX = right; } // setup z commands if (zRange <= 0) { approachTargetZ = down; departTargetZ = up; } else { approachTargetZ = up; departTargetZ = down; } |
Azriel~