Passing a blitzcommand through a string
BlitzMax Forums/BlitzMax Programming/Passing a blitzcommand through a string
| ||
Say I have a function called executecommand(command$), and I execute it like this by pressing a button or something within a gui: if button.pressed then executecommand(command$). Now, command$ is a field within the button type, and holds the command to be executed, for instance "startgame()". How can this be done? What sort of magic should I do to have blitzmax understand the string as a command? |
| ||
You'd have to parse the string and given the command you specify, have it call the appropriate actual Function/Method.Select command Case "startgame" StartGame() Case "highscores" HighScores() End Select Or something similar... but either way, you'd need logic hard-coded somewhere. Unlike with say, Java, which lets you, through reflection, create classes and call methods, access fields, etc... using strings. |
| ||
Alright thanks brucey (seems like you keep answering my questions haha). That's what I've done initially, but I had hoped it was possible to not have to do that. See I'm trying to write a gui for a gui so to speak, where you can create new windows etc. inside of the 'game'. When you create a button you're asked to type in the command to execute - but I guess since it's not possible to pass the actual commands the user writes here, the user will have to modify the sourcecode by hand and make the proper selects. /sigh |