Why doesn't this work?

Blitz3D Forums/Blitz3D Programming/Why doesn't this work?

Captain Wicker (crazy hillbilly)(Posted 2012) [#1]

AppTitle "Diffuculty Selection Menu:"

Graphics 640,480,16,2

Print "Please Input Easy, Medium or Hard to select your diffuculty level"

program = Input("")

If program = "easy" Then ExecFile("easy.exe")
If program = "medium" Then ExecFile("medium.exe")
If program = "hard" Then ExecFile("hard.exe")

why doesn't this work?


GfK(Posted 2012) [#2]
Are you seriously having three separate executables?!

Don't even worry about why this doesn't work (whatever "it doesn't work" means). It's an awful way of doing it.


PowerPC603(Posted 2012) [#3]
It doesn't work because you created "program" as an integer variable, which cannot hold a string.

Try this instead:
program$ = Input("")


The first time you use a variable, you also automatically declare it (allocate memory-space for it).
Any use after that, you won't need to re-define the type of the variable ($ for string for example), so there won't be a need to have "program$" in the If-statements.

Last edited 2012


Kryzon(Posted 2012) [#4]
Besides it not being a string-type variable like PowerPC mentioned, when you need to compare a single value against several possibilities you can resort to a SELECT:

[bbcode]
;[...]

Local program$ = Input("")

Select program$
Case "Easy"
;Do whatever the program should do for an 'easy' setting.
Case "Medium"
;[...]
Case "Hard"
;[...]
End Select
[/bbcode]
Much cleaner than using several IFs.


Captain Wicker (crazy hillbilly)(Posted 2012) [#5]
program$ = Input("")

that is right! thanks for the reminder PowerPC603 :)
Are you seriously having three separate executables?!

so that users can open the game at any difficulty without having to configure it in case they dont want to have to configure the program each and every time they want to play. ;)

Last edited 2012


Yasha(Posted 2012) [#6]
If the game is properly designed, difficulty is something that one or two variables ought to be able to change. Twelve bytes instead of three megs, and better performance and integration to boot. After all, how often do you go into the options menu to adjust game difficulty? Unless it's the Elder Scrolls (which are shoddily programmed games, even if the design is beautiful, let's be honest), the answer is "not often"! Difficulty is something you choose once and let the game engine handle, cranking things up or down as required. It should most definitely not involve a recompile.

For anything short of a strategy game, or a very involved shooter, difficulty is probably a matter of stats. That means all you really need to do is multiply a fixed figure by the difficulty factor, and the game adjusts itself.


H&K(Posted 2012) [#7]
I hope you are converting the input string to either lower or upper case before the comparison? (I assume you are and have simply cut it out from this example)


PowerPC603(Posted 2012) [#8]
As for difficulty settings, you can have variables to hold multiplier values or something like that.
If you create a game to kill monsters for example, you can set the Damage-multiplier for easy to 0.5, normal would be 1.0 and hard would be 2.0.

You don't have to hardcode these values as well.
Your game could have 3 separate text-files which hold the values required for each difficulty setting.
You could have Easy.dat, Normal.dat and Hard.dat.

When the player starts the game and selects a difficulty setting, you could load the proper difficulty-file and store the values into the correct variables.
When the player progresses through the game and saves his game, you could save one extra field in his savegame that indicates the difficulty setting (1 = easy, 2 = normal, 3 = hard).

When he wants to load his game again, your game should be able to read that value and load the proper difficulty-file based on that value.

I've honestly never seen a game yet that has 3 different exe files for each difficulty setting.