function and types help
BlitzMax Forums/BlitzMax Beginners Area/function and types help
| ||
Hi, this might be pretty easy, or a silly mistake, but can I ask why I can't make the code in the updatePlayers() run.Function UpdatePlayers() If player.hasBall = 1 ballX = player.x ballY = player.y End If End Function Function DrawMatchGFX() For Local player:playerType = EachIn playerList UpdatePlayers() DrawImage(imgPlayer,player.x,player.y,0) Next DrawImage(imgBall,ballX,ballY,0) End Function |
| ||
I've just tried this, but it doesn't work well, it just runs for each object, and not the one specific object that has 'player.hasBall = 1'Function UpdatePlayers(hasBall:Int) If hasBall = 1 ballX = player.x ballY = player.y End If End Function Function DrawMatchGFX() For Local player:playerType = EachIn playerList UpdatePlayers(player.hasBall) DrawImage(imgPlayer,player.x,player.y,0) Next DrawImage(imgBall,ballX,ballY,0) End Function |
| ||
ah I think I've worked it out with: Function UpdatePlayers(hasBall:Int,playerx:Int,playery:Int) |
| ||
Or something like this...Type Drawable Field x:Int Field y:Int Field img:TImage Method draw() DrawImage img, x, y End Method End Type Type BallType Extends Drawable End Type Type PlayerType Extends Drawable Method update(ball:BallType) If hasBall Then ball.x = x ball.y = y End If End Method End Type Function UpdatePlayers() For Local player:playerType = EachIn playerList player.update(ball) Next End Function Function DrawMatchGFX() For Local player:playerType = EachIn playerList player.draw() Next ball.draw() End Function |
| ||
Where are the variables player and ball defined? Are they global?If player.hasBall = 1 ballX = player.x ballY = player.y End If This does not find the player for which hasBall is 1. It checks whether one variable you have provided called "player" has the ball, but I can't see where this variable is coming from. |
| ||
Are they global? Since he's using Functions, one has to assume everything is global... |
| ||
I wasn't sure if he meant he could get it to compile or not. |
| ||
Ah :-) I hoped to fill in a bunch of gaps with my example - I just like to make things up! |
| ||
thanks brucey, I'll have to have some practice using methods, as it does look a lot easier |