Variables in functions are
local.
So a variable you use in a function is for that function only, outside of the function that value will be null. To make a function affect the other code, you either need to declare you variable as
global or use the function to return the value.
This shows both ways:
`Variable "A" is not global, it will only work in the main body of code, NOT in functions
A = 5
`Variable "B" has been declared as global, it will be recognised by the whole program
Global B = 5
Print "A non-global variable:"
Print A
`Use can use a global variable exactly the same as any other
Print "A global variable:"
Print B
Print "The global variable is used in a function"
`The function doesn't need any parameters, it just takes the global variable
Test()
Print "This is the result:"
Print B
Print "Then, another way, pass a variable('A') to a function, and have the new value returned"
`The test2() function, needs a parameter and as it returns a value, we assign it to a new
`variable.
C = Test2(A)
Print C
Wait Key
End
Function Test()
B = B*2
EndFunction
Function Test2(Num)
C = Num*2
`Just put the value you want returned after the "EndFunction" command
EndFunction C
You can also use constants:
#constant whatever = "whatever"
or even:
`You can even use constants to hold commands
#constant hello = Box 50,50,75,75
Print "Press Enter to draw a box"
Repeat
Until ReturnKey() = 1
`This now draws a box
hello
Repeat
Until ReturnKey() = 0
Wait Key
Hope that helps abit.
#Edit, this all works in DBP, and should probably be the same in DBC too. But i haven't checked.
Cubes with guns? Something isn't right...