Hello all together, i am training with types and functions, i wan?t do the following and i would be happy if someone helps
The code to train is very simple:
+ Code Snippettype player
sprite as integer
posx as integer
posy as integer
endtype
Global player1 as player
Global player2 as player
global targetx=1000
global choose
global moveright=1
setup_players()
global d
do
update_players(1,player1)
update_players(2,player2)
Sync()
loop
function setup_players()
player1.sprite = createsprite(loadimage("kugel_rot.png"))
player2.sprite = createsprite(loadimage("kugel_blau.png"))
player1.posx=200
player1.posy=200
player2.posx=600
player2.posy=200
endfunction
function update_players (a as integer, d as player)
if moveright=1 and choose=a and d.posx < targetx
inc d.posx, 5
elseif choose=a
moveright=0
endif
setspriteposition(player1.sprite,player1.posx,player1.posy)
setspriteposition(player2.sprite,player2.posx,player2.posy)
endfunction
My plan is, that i have the update_players function 1 time and call with the player1 and player2.
The choose values with 1 and 2 works, but the player1 and player2 doens?t work, the sprites are not moving but the compiler don?t give an error.
Is there a way to handle this? This would shorten the code extremely.
Thanks for your help.