DrawImage using Array refrence bug/Error

BlitzMax Forums/BlitzMax Beginners Area/DrawImage using Array refrence bug/Error

RedWizzard(Posted 2016) [#1]
HI,

I am trying to make my games player objects (seprated from all objects)
In the game you can choose your playercolor / type

I have made it so that the type of your player is a picture and your color is from a frame whitn that picture (picutres image is 25*25 frame 200)
So using type 1, color red is Image_1,Frame 1
Using type 1,color bleu is Image_1,frame 2 ectra

I setup a Playergrid[x,y] and a PlayersSdata[9],10 array
i have my drawplayer function wich draws the player
DrawPlayer(Player,X,Y,Playertype)

This all works fine until i use my updateplayer stuff function
The main game loop starts and loops troug varoiuse functions

Here is the strange thing. when i hardcore the DrawPlayer and PlayerSdata
into the main game loop it works fine.

If i use the same style of code in my UpdateplayerStuff function
it will work but inccorect showing ALL types of player pictures
instead of only a knight or a wizzard.

I have added '**NOTE in my codes to explian my problem

The Main game loop showing both examples
[code]
'****************************************Time Picture clock


SetScale( 2,2 )

MapupdateLayer
'**NOTE The UpdatePlayerstuff shown in ohter code exmaples
'**NOTE does not work correctly

UpdatePlayerStuff KeyLR,KeyUD

UpdateObjectselectB SliderValue(slider)
BuildThis ItemC,KeyLR,KeyUD,MapLayer
UpdateItemVieuw ItemC,Mxz,MYz
MakeWall "C:\GameBuild\WizzardGame\DataFiles\SteelWall.PNG",2
DoInfo
SetLayer
If ButtonState (DataChekbut)=True Then ReportLayerinfo KeyLR,KeyUD
'**NOTE the hard coded Drawplayer wich works fine
DrawPlayer 1,2*50,2*50,PlayerSdata[1,1]
DrawPlayer 2,3*50,2*50,PlayerSdata[2,2]
DrawPlayer 3,4*50,2*50,PlayerSdata[3,3]
DrawPlayer 4,5*50,2*50,PlayerSdata[4,4]

DrawImage StBox,MXz,MYz
DrawText "WizzGameEngine 0.5",75,10

GUI_MouseGrid()

Flip 0
[/Code]

[Code]
Function DrawPlayer(Player:Int,X:Int,Y:Int,PlayerType:Int)

Local Picture:TImage=PImages[PlayerType]

If Player=1 Then DrawImage Picture,X,Y,0 'red
If Player=2 Then DrawImage Picture,X,Y,1 'blue
If Player=3 Then DrawImage Picture,X,Y,2 'green
If Player=4 Then DrawImage Picture,X,Y,3 'yellow
If Player=5 Then DrawImage Picture,X,Y,4 'Purple
If Player=6 Then DrawImage Picture,X,Y,5 'orange
If Player=7 Then DrawImage Picture,X,Y,6 'brown
If Player=8 Then DrawImage Picture,X,Y,7 'teal

End Function


Global PlayerGrid[GridMax_X,GridMax_Y]

'*****setup test data for players

'**NOTE setting up testplayer items at Grid X/Y
Playergrid[1,2]=1
Playergrid[1,3]=2
Playergrid[2,4]=3
Playergrid[3,5]=4
Playergrid[4,6]=5
Playergrid[1,7]=6
Playergrid[1,8]=7
Playergrid[1,9]=8

PlayerSdata[1,1]=1 '**NOTE this is the player type 1=Knight 2wizzard 3 monk
PlayerSdata[2,1]=2
PlayerSdata[3,1]=3
PlayerSdata[4,1]=3
PlayerSdata[5,1]=3
PlayerSdata[6,1]=2
PlayerSdata[7,1]=1
PlayerSdata[8,1]=3


Function UpdatePlayerStuff(KeyLR:Int,KeyUD:Int)
Local x;Local y;Local z;Local p
Local scroll_LR=KeyLR
Local scroll_UD=KeyUD
'Ft=Ft+Rnd(12)
For X = 1 To 25 'changed from 25
For Y = 1 To 12 'from 12
For P = 1 To 8
Print "data" + Playersdata[p,1]
DrawPlayer PlayerGrid[X+scroll_LR,Y+scroll_UD],X*50,Y*50,PlayerSdata[p,1]
Next
Next
Next

End Function


[/Code]


Example picture of problem