problem with Create Button

BlitzPlus Forums/BlitzPlus Beginners Area/problem with Create Button

matthew(Posted 2007) [#1]
I want my program to make a button of the name of the file it loads but if I do filein = CreateButton() it will filein be the variable of the button

Newbuttons = ReadDir("C:\Program Files\BlitzPlus\games\Editor\buttons\regsize")
Repeat




file$ = NextFile$(Newbuttons)
If file$="" Then Goto main
a = a + 1
filein = ReadFile(file$)
Read1$ = ReadString(filein)
Read2 = ReadInt(filein)
Read3 = ReadInt(filein)
Read4$ = ReadString(filein)
If Read4$ = "jumponpanel" Then * = CreateButton(Read1,Read2,Read3,100,500,jumponpanel)
If Read4$ = "invinciblepanel" Then * = CreateButton(Read1,Read2,Read3,100,500,invinciblepanel)
If Read4$ = "bosspanel" Then * = CreateButton(Read1,Read2,Read3,100,500,bosspanel)
If Read4$ = "headpanel" Then * = CreateButton(Read1,Read2,Read3,100,500,headpanel)
If Read4$ = "jumppanel" Then * = CreateButton(Read1,Read2,Read3,100,500,jumppanel)
If Read4$ = "backgroundpanel" Then * = CreateButton(Read1,Read2,Read3,100,500,backgroungpanel)
If Read4$ = "tubespanel" Then * = CreateButton(Read1,Read2,Read3,100,500,tubespanel)
If Read4$ = "personpanel" Then * = CreateButton(Read1,Read2,Read3,100,500,personpanel)
If Read4$ = "pickuppanel" Then * = CreateButton(Read1,Read2,Read3,100,500,pickuppanel)
If Read4$ = "poweruppanel" Then * = CreateButton(Read1,Read2,Read3,100,500,poweruppanel)
If Read4$ = "pointerspanel" Then * = CreateButton(Read1,Read2,Read3,100,500,pointerspanel)
CloseFile(filein)
; * = the variable that I want to make a button of



Forever

.main
CloseDir(Newbuttons)


Andy_A(Posted 2007) [#2]
Use an integer array instead of "*"
(e.g. btn%(a) )


matthew(Posted 2007) [#3]
It doesn't work. It just thinks that btn%(a) is a function.


Andy_A(Posted 2007) [#4]
That is correct. If you do not declare and dimension the array before using it, that's the error you'll get.

Put this in at the beginning of the program.

Dim btn%(500)

This allocates 2012 bytes of storage for 501 long integers (4 bytes for each integer, long pointer to memory and other overhead)


Adam Novagen(Posted 2007) [#5]
Incidentally, it's not necessary to declare an array as an integer with "%". If you declare an array, or any type of variable, it's automiatically an integer var unless you specify "#" or "$". Not that it really matters either way, it just saves you a few keystrokes. ^_^


Andy_A(Posted 2007) [#6]
The reason for the declaration is not necessarily for the compiler but for error checking and detection later on. In a large program hunting down whether a variable is an integer or a float can be a needlessly time consuming process. That's why BlitzMax has the "Super Strict" option.