stuck in a silly routine

Blitz3D Forums/Blitz3D Beginners Area/stuck in a silly routine

RGF(Posted 2009) [#1]
The question is:

Which procedure should I use for declaring 100 global variables, named from number0, number1, number2... ...number99 ??

Of course, typing "Global number0, number1, number2... " is not a valid answer :)!

Each of these variables will later be used for creating 100 little sized images
number0=createimage(10,20,1)


big10p(Posted 2009) [#2]
Use an array instead.


RGF(Posted 2009) [#3]
Thank You, that was what I was using:

Dim nv(99)
For i=0 To 99
nv(i)=CreateImage(20,20,1)
SetBuffer ImageBuffer(nv(i))
Color 50,50,50
Rect 0,0,20,20,1
Color 255,255,255
Text 0,0,i
SetBuffer BackBuffer()
Next

But I was wondering about variable naming... tinkering with strings and so...


Stevie G(Posted 2009) [#4]
Your could use:

MyImages = CreateImage( 20,20,100 )

And draw each of the 100 images within the 200x200 space for easy access. They are accessed via frames 0-99 so to draw image 100 in the sequence use:

DrawImage MyImages, X, Y, 99

It really depends on what additional information you need to know about each image?

Stevie


Warner(Posted 2009) [#5]
Is each image different? Else you only need one image.
And beside arrays you could also use a user type. If you're planning on deleting/creating objects while the program is running, types are easier.
On your original question: you can't use strings in variable names, however you could create a program that writes a textfile:
ff = writefile("test002.bb")
for i = 0 to 99
writeline ff, "image" + i + " = createimage(20,20,1)"
next
closefile ff



RGF(Posted 2009) [#6]
Thank you very much, for both answers. I`ve tried, and combination of both ideas (type+frames(0-99)) gives very fast and nice results!

The program is an inventory, displaying icon and text, old Diablo-style...

@Warner: very clever! by creating text files, strings can be used as variable names, that's just what i meant in the first post!

Thanks!