Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / What am I doing wrong here? Using Types, Arrays and Constants.

Author
Message
Urlforce Studios
17
Years of Service
User Offline
Joined: 16th Oct 2006
Location:
Posted: 30th Aug 2008 07:57 Edited at: 30th Aug 2008 07:58
I am attempting to make a console for my game, using an array to keep track of my commands, as I will,in the future that is, add in a scripting system.

What happens is the game loads and you can use a command prompt to play, when I type in the correct command, it crashes the game,, when I just want it to close it the "good" way. I'm prototyping the method so I can add on more commands later.

I am 90% sure it's possible because I believe had the problem solved at one point, but before I could save it the editor crashed on me so I lost it. 3 hours later I still haven't been able to work it out. Any ideas?



Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 30th Aug 2008 08:50
Its probably because you select a string but check it against an integer. So even if you were to type in "1" it wouldn't work but I think you want to type in "exit"...right? So you would have to loop through your array of commands to find a match and pass the variable i instead (making sure the index number of the array matches the number of the command).

Hope that made some sense

Urlforce Studios
17
Years of Service
User Offline
Joined: 16th Oct 2006
Location:
Posted: 30th Aug 2008 08:56 Edited at: 30th Aug 2008 08:58
So there's no use of a constant?

Where did I check it as a integer? I don't understand. Sorry.

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 30th Aug 2008 09:03
Well the constant quit is 1 which basically makes it an integer by default. If you were to put quotes around it then it would make it a string.

You don't have to use a constant although you can if you like using words making it easier to understand.

Urlforce Studios
17
Years of Service
User Offline
Joined: 16th Oct 2006
Location:
Posted: 30th Aug 2008 09:09
Would using constants as commands be better than using an array?
for example


Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 30th Aug 2008 09:12
It probably would be much easier.

Urlforce Studios
17
Years of Service
User Offline
Joined: 16th Oct 2006
Location:
Posted: 30th Aug 2008 09:15
Would I be able to set up files and parse them like I would if they were in an array?

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 30th Aug 2008 09:26
Yes, but you would have to create your own parser to split the strings into parts, most likely storing them into an array. This would allow you to have parameters for commands and such. Split the string so the command is a separate string from the parameters, the parameters also being separate from other parameters. I would look into, if you don't have it already, downloading IanM's Matrix Dlls as he has some commands that could help with splitting strings up but I haven't looked into the commands to much so I don't know how much of the work it does for you.

Urlforce Studios
17
Years of Service
User Offline
Joined: 16th Oct 2006
Location:
Posted: 30th Aug 2008 09:28
Thanks I'll check that out! If anyone else has more suggestions please share them!

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Sep 2008 07:00
You'll want to use constants instead of an array and the reason for that is when determining what action to perform when a user types the commands.

True it is easier to check for a valid command when using an array, but you won't technically know which command has been typed and therefore know which action to perform. Here's how I did it for a spaceship game I did once.




Urlforce Studios
17
Years of Service
User Offline
Joined: 16th Oct 2006
Location:
Posted: 3rd Sep 2008 20:04
Thanks Phaelax Excellent example helped me out alot.

Login to post a reply

Server time is: 2024-09-27 20:26:59
Your offset time is: 2024-09-27 20:26:59