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.

DarkBASIC Professional Discussion / Need help moving on after and if statement in my text based game

Author
Message
Wizzerd
15
Years of Service
User Offline
Joined: 25th Jan 2011
Location:
Posted: 20th Oct 2011 09:36
Ok so Im just learning and trying out DBP

I started a basic text based game, to try to get the syntax down and see how everything works.

I am stuck on my If cycle,

I have this as my code.
The Issue is I dont know how to continue after the endif, I want the user to be able to continue the story if they chose to take the mission by pressing 1 I want the screen to clear and have the print "Lets get you in to the chopper to appear"

Any ideas?
Print
Print "We need you to investigate "

Print "Will You Investigate"

Input "Press 1 for yes or 2 for no and hit enter: ", FirstMission

If 1=FirstMission
Print "Ok Then Lets Go"

Else
Print "Game Will End"
wait key

endif

cls

Print "Lets get you in to the Chopper"
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 20th Oct 2011 12:07
Hi Wizzerd, welcome to the forums!

Can I suggest you take a look and post your questions here:
DBPro Newcomers

It's a great introduction to the forums and DBPro!

You need to look at the "keystate()" command for your problem but I would suggest trying some of the tutorials available in the newcomers area before getting too stuck into your first project.

Good luck!

NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 23rd Oct 2011 20:44 Edited at: 23rd Oct 2011 20:45
As you're new to programming, I'd suggest you get in the habbit of indenting your code as follows:



Indenting code may seem like a very small detail, and yes the code functions exactly the same with or without it, but when you get to writing a big program, it'll be far easier to read and find mistakes/bugs in it.

IlluminatedFX.com
For web design and graphic design services
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 23rd Oct 2011 21:29 Edited at: 23rd Oct 2011 21:35
Not sure why everyone is giving you examples on using the KeyState command. While it's used more often and has better functionality, it wasn't the question you had asked, nor does it answer what was going right/wrong for you... except for the fact that anything other than entering 1 will cause the game to end (not just 2). But in keeping with the commands you were learning about there are other ways to ensure only 1 or 2 are acceptable choices.

Your code was fine. You just weren't seeing the last print statement because the program would end and close before you could see it. Since you really don't have a game-loop at the moment,, the best that I could do to show you that your code was working,, was to put a wait key command at the end. this prevents your app from closing until a key is pressed.

I also added an end command to else condition. If it wasn't there the program would execute the cls and the following print command after printing "Game Will End".




Also, while it works fine this way. Most often you will find the variable on the left of the evaluation

if FirstMission = 1

Your signature has been erased by a mod please reduce it to 600 x 120.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 23rd Oct 2011 21:50 Edited at: 24th Oct 2011 14:23
Edit
Edited out a poorly concieved example,, that introduced the possibility of an infinite recursive call that could lead to a call stack overflow.

Your signature has been erased by a mod please reduce it to 600 x 120.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 10:38
Quote: "Now I generally don't code like that. And I would have probably used keystate and a select-case statement... But I think it's more helpful at times to stick with the direction the poster is going. It's great to offer better suggestions, after helping them with their approach."

I prefer to point someone in the right direction before they go in the 'wrong' direction. Each to their own...

Why show someone how to code in a way you wouldn't use yourself?

Personally I prefer to display any text as part of a loop rather than using the Input command which I find unintuitive and inflexible. I suggested "Keystate" for those reasons.

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Oct 2011 11:52 Edited at: 24th Oct 2011 12:06
Quote: "I prefer to point someone in the right direction before they go in the 'wrong' direction. Each to their own...

Why show someone how to code in a way you wouldn't use yourself?"


Pointing them in the right direction doesn't mean ignoring their question. The poster is working through different commands trying to learn how they work. They thought that theire code wasn't working. When in fact it worked fine. The part that the poster was having trouble with was not seeing the results. I don't see it as helpful to not explain this to the poster. To suggest other commands only would lead the poster to believe he was on the wrong track, or that the commands didn't work as he understood them nor could those commands accomplish the given task. Neither of those was true.


The answer to your second question, is because the way that I would do things, might completely confuse the original poster. Doing more harm than good. And again it wouldn't address the problem he/she was having with their code. There are many times that I or anyone else on this board answers questions or helps fix bugs in code that is far from the solution they would chose. Sometimes there is time, or it's appropriate to offer alternatives given the assessment of the users experience level. I'm not against offering a better solution, I do it all the time.

But with someone who is just learning the commands I think it's also important to answer their question based around their code. Especially,, when the code did what they wanted it to do.

Since you like questions. "Why didn't you answer that their code was working?".

To each his own....

Your signature has been erased by a mod please reduce it to 600 x 120.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 12:14 Edited at: 24th Oct 2011 14:21
Quote: "Pointing them in the right direction doesn't mean ignoring their question."

I didn't intentionally ignore the question. I actually thought that the code was not using the results from the Input;

Where he put
"If 1=FirstMission"

Quote: "And since you like questions. "Why didn't you answer that the code was working?". To each his own...."

I thought he was expecting "1" to be a value from input not the "FirstMission" part. Looking again I realise that he just had the equation the other way around to how I expect to see it which is what confused me. I never claim to be exempt from making mistakes

I never intentionally ignore a person's question and try to help wherever I can. You were suggesting that "keystate" was a bad suggestion and then contradicting yourself which I thought was even more confusing.

I can see that my suggestion was not the solution to their problem but that was a simple misunderstanding there is no need to turn it into an argument.

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Oct 2011 13:06 Edited at: 24th Oct 2011 15:00
You're the one who called me out specifically.

I wasn't worried about stack overflow for this type of an example. Especially with no function arguments,, but glad you can pick that up.

How long before I hit an call stack overflow????

Your signature has been erased by a mod please reduce it to 600 x 120.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 13:16
Quote: "You're the one who called me out specifically."

Sorry if you thought I was responding in a bad way, I just thought it was odd that you suggested "keystate" was a bad suggestion. I was simply responding to that by saying why I had made the suggestion. I also wondered why you would tell someone to code in a way you wouldn't use yourself, I wasn't calling you out or being nasty. You have explained that and I understand now, thank you.

Quote: "Wasn't worried about stack overflows for this type of an example."

Could you remove it from the code anyway as it might screw someone up in the future.

Quote: "But glad you can pick that up."

Again, there's no need to be churlish. That's a clear dig at my abilities and uncalled for.

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Oct 2011 13:43
Nah, not going to remove it from my code. I'll wait for the call stack overflow....



Your signature has been erased by a mod please reduce it to 600 x 120.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 13:46 Edited at: 24th Oct 2011 13:51
Not biting...

EDIT: Thanks for removing the offensive remark

EDIT 2: OK I'm biting.

Quote: "How long before I hit an call stack overflow????"

If the code is in someone's game and it gets played for a while not long really. Are you suggesting it's better to leave it in because it will take a while before it crashes?

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Oct 2011 13:53
ok, not baiting

Your signature has been erased by a mod please reduce it to 600 x 120.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 13:55 Edited at: 24th Oct 2011 13:56
I think we'd better leave it there as this is completely obscuring a simple request for help which has been addressed.

Peace?

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 14:08
Any chance we can end this on a nice note and agree to disagree? I can see that you won't edit the bad code as a matter of principle but I'd rather stay friendly than end this as it is... I don't want any bad feelings to go beyond this silly debate.

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Oct 2011 14:15
Surely.
And I edited out the code. It was poorly concieved!!! And not at all intentional. I was trying to help just as you were, and I typed it up right before leaving for work, without giving it much thought. If you would be as so kind to remove it from your post, I would appreciate it.

And have a good day. I mean that sincerely. I don't have any issues with you baxslash.

=)

Your signature has been erased by a mod please reduce it to 600 x 120.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 14:19
Glad we are cool @zenassem. Thanks.

I generally make mistakes like I made in my first post because I'm in a rush too.

I'll edit my post as requested...

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Oct 2011 14:26 Edited at: 24th Oct 2011 14:27
Thanks.

btw in that example I believe it overflowed on the 523461st call. I'm not sure that is an exact measure of what the original code would have done, but I think it's close. I actually took out the print and sync statements to get to it.

Your signature has been erased by a mod please reduce it to 600 x 120.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 14:36
Nice, I make that about 2 and a half hours of gameplay at 60fps if it's only called once per loop! I think I've played COD for that long a few times... a few other games for much longer when I had the time

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Oct 2011 14:58


At least we came to our senses. Ah, perhaps you before me, but somehow we got there together. And that is truly a decent amount of game time,, I actually had more leg to stand on than I thought. Lol.

Your signature has been erased by a mod please reduce it to 600 x 120.

Login to post a reply

Server time is: 2026-07-10 23:33:24
Your offset time is: 2026-07-10 23:33:24