Constant arrays

BlitzMax Forums/BlitzMax Beginners Area/Constant arrays

Czar Flavius(Posted 2009) [#1]
Can we have them?
Const cash_value:Int[] = [5000, 10000, 15000, 20000, 25000, 50000, 75000, 100000]
"Compile Error: Constant initializers must be constant"


Jesse(Posted 2009) [#2]
I tried that long time ago. It's not possible but that would be nice.


Czar Flavius(Posted 2009) [#3]
Const cash_value1 = 5000
Const cash_value2 = 10000
Const cash_value3 = 15000
Const cash_value4 = 20000
Const cash_value5 = 25000
Const cash_value6 = 50000
Const cash_value7 = 100000
Makes the Czar sad :'(


_Skully(Posted 2009) [#4]
Just make it global...


Czar Flavius(Posted 2009) [#5]
But Consts are faster than Globals!


Gabriel(Posted 2009) [#6]
If you've optimized your game to the point where a global array vs a constant array is your greatest concern, it's finished. Ship it.


Czar Flavius(Posted 2009) [#7]
I HAVE OCD THEY MUST BE CONSTANTS AT ALL COSTS.


_Skully(Posted 2009) [#8]
Obsessive Constant disorder?


ImaginaryHuman(Posted 2009) [#9]
While we're at it, today I decided I need a `Welse` command... ie

While something=something else
'do stuff
Welse
'do something else
Wend

Becauuuuuuse... while is like an `if` statement, so why not have a section of code that gets run when the while condition is no longer met, so that you can actually use it in place of an if-else-endif?


TaskMaster(Posted 2009) [#10]
Wouldn't anything after you put after the Wend basically be the Welse part? Since it is going to exit the While loop after doing the Welse anyway?!?!


Czar Flavius(Posted 2009) [#11]
If you mean it should run the Welse if the While condition is not met at the first instance, you could try this:
If Not condition
	'code
Else
	Repeat
		'code
	Until Not Condition
End If



ImaginaryHuman(Posted 2009) [#12]
No, you only want to do the welse part if the while was not executed. So it'd be like...

.Top
If condition
'do stuff
goto .Top
else
'do stuff
endif

Pretty much like Czar said. I tend to use while's to replace IF statements so it'd just be handy to be able to incorporate an `else` action.


Jesse(Posted 2009) [#13]
I am sure he was just being funny. ..??


Czar Flavius(Posted 2009) [#14]
Why not use Ifs?


Jesse(Posted 2009) [#15]
I was a few seconds too late. I meant that about IH but I guess not


ImaginaryHuman(Posted 2009) [#16]
Of course you can use if's but if you want to do an `if-loop` such as While, then you have to separate out the if-else from the looping. Just an idea.