Re-Loading an Array problem

BlitzMax Forums/BlitzMax Beginners Area/Re-Loading an Array problem

Emmett(Posted 2005) [#1]
The isolated parts of the prolem:

incbin "media/tiles.png"
#resetlevel
global frames[]=[3,5,1,8,7]
global tiles
tiles = LoadAnimImage ("incbin::media/tiles.png",126,25,0,5)
repeat
drawimage tiles,x,y,frames[n]
if done with that tile frames[n]=0
if want to start over goto resetlevel
until escape

The problem is frames[] is not resetting to =[3,5,1,8,7] but instead remains =[0,0,0,0,0].
Everything else in the game resets to the start new game values, only frames[] is not resetting.
How do I reload that array?


tonyg(Posted 2005) [#2]
That's not exactly isolated code is it..
This works...
#resetlevel
Global frames[]=[3,5,1,8,7] 
Repeat 
  For n=0 To 4
    Print frames[n]
  Next
  Goto resetlevel
Until KeyHit(KEY_ESCAPE) 

so it must be some other part of your code.


Beaker(Posted 2005) [#3]
I suspect the bug is here:
if done with that tile frames[n]=0

:)


Dreamora(Posted 2005) [#4]
does frames[] = new [3,5,1,8,7]
work?

otherwise you need to frames[] = null it first before goto


Emmett(Posted 2005) [#5]
Thanks All for the input!

@tonyg the problem is not using the initial array
When you do this:
#resetlevel
Global frames[]=[3,5,1,8,7] 
Repeat 
  For n=0 To 4
    Print frames[n]
    frames[n]=0
  Next
  Goto resetlevel
Until KeyHit(KEY_ESCAPE)

Then 3,5,1,8,7 will only print 1 time

@Beaker - Yea I know but it is part of the function of the game

@Dreamora - frames[] = new [3,5,1,8,7] - does not work
Could not get frames[] = null to work either

Is the placement of #resetlevel the problem?

I've tried moving frames[]=[n,n,n,n] all over the place with limited success. But still it won't re-load.

I know if it is done right it will work. I will mull over this some more this evening after work.


Dreamora(Posted 2005) [#6]
hmm there is something that is missing:

try a flushmem directly after #resetlevel

and then try the ideas above again ... perhaps this helps.


skidracer(Posted 2005) [#7]
global frames[]=[3,5,1,8,7]

being a global initializer will only ever execute once at program startup where as

global frames[]
frames=[3,5,1,8,7]

should reinitialize the array every time the line is executed


Emmett(Posted 2005) [#8]
Thanks skidracer - That is the answer to the problem.

By disconnecting the "initializer" global frames[] from the "loader" frames=[3,5,1,8,7] I can now move and load frames anywhere.
So I moved frames=[n,n,n,n,n] into the same function that loads a set of tiles that are not in random order which gets called from the main loop.

Moved the #reset label just above the main loop. It's a done deal now.

BTW:
being a global initializer will only ever execute once at program startup

Could someone expand on this?