Quote: "Okay I got movement down, but I am having problems with functions.
Why does this work"
Unfortunately this thread showed no new messages so your new messages... so this thread has probably been skipped by a lot of people.
Function Lesson:
The following won't be pretty... but here goes.
When you define things outside of the function like "lx=25" lx will be 25 outside of the function... but inside the function it will start at equaling zero. Any changes inside the function will work... but when it gets out of the function it will still be what lx equaled before entering the function.
For Pro it's easy to just define the variable as global so it can be used inside a function.
global a=1
b=1
print "Before the Function"
print " A = "+str$(a)
print " B = "+str$(b)
ChangeStuff()
print " "
print "After the Function"
print " A = "+str$(a)
print " B = "+str$(b)
wait key
function ChangeStuff()
print " "
print "Inside the Function (Before Change)"
print " A = "+str$(a)
print " B = "+str$(b)
inc a,49 ` Increase a by 49
inc b,49 ` Increase b by 49
print " "
print "Inside the Function (After Change )"
print " A = "+str$(a)
print " B = "+str$(b)
endfunction
You can also have functions return information... you can have as many variables go into a function but can only have one variable return information.
a=1
b=1
print "Before the Function"
print " A = "+str$(a)
print " B = "+str$(b)
a=ChangeStuff(a,b) ` Make a equal the returned number from the function
print " "
print "After the Function"
print " A = "+str$(a)
print " B = "+str$(b)
wait key
function ChangeStuff(x,y)
print " "
print "Inside the Function (Before Change)"
print " X = "+str$(x)
print " Y = "+str$(y)
inc x,49 ` Increase x by 49
inc y,49 ` Increase y by 49
print " "
print "Inside the Function (After Change )"
print " X = "+str$(x)
print " Y = "+str$(y)
endfunction x
In the above snip the function is called with "a=ChangeStuff(a,b)". The function itself is made with "function ChangeStuff(x,y)"... so inside the function it defines "x" as whatever "a" is and "y" as whatever "b" is. Inside the function "x" and "y" are changed... but because the end of the function has "endfunction x" it returns whatever "x" has become while going through the function. So the line that called the function "a=ChangeStuff(a,b)" is basically "a=x" (the "x" from inside the function).
End of Lesson
I personally would just put all the player stuff in an array for ease of use. Arrays are automatically defined as global.
User Defined Type:
type PlayerStuff
x as integer
y as integer
gravity as boolean
endtype
Player as PlayerStuff
Player.x=25
Player.y=200
Player.gravity=1
A regular array:
dim Player(0,2)
Player(0,0)=25
Player(0,1)=200
Player(0,2)=1
Hope this helps.