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 / String + Variable Addition ( DB Noob )

Author
Message
Swampert
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location: Somewhere in the Interwebs
Posted: 26th Nov 2009 20:29 Edited at: 26th Nov 2009 20:31
I'm sure this is probably going to be a very stupid question but hey, that means that it has an easy answer.

I just started with DarkBASIC after coming from C++ ( Dark GDK ). C++ is really going down the tubes I'm telling you. I'm going to be taking a class on it later then I'll settle down and maybe create my own game engine but I'm droning on now.

I'm making a little text based game for my friend to start out with DB and for some reason, if you lose the game, instead of printing out "You have lost, the winner is ";ePoke$, it does nothing and executes my replay function. It also does not display the winning message. What am I doing wrong?

Type Advantage is where the winning/losing comes in Fire-Water-Grass etc.


Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 26th Nov 2009 20:50 Edited at: 26th Nov 2009 20:51
Edit : never mind

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th Nov 2009 21:26
Hello,

I'm actually surprised this would run at all in DBC. For one, you are using the comment indicator '//' which doesn't exist in DBC and will cause an error. To turn a single line into a comment either use
rem blah blah blah
or
use the reverse single quote (the key next to the 1 key)
` blah blah blah
If you want to add a comment on the same line after code, then separte the code and the comment with a ':'

To remoark entire blocks of text use


And number 2, in your function:



You have a reference to 'game' which does not exist inside the function. Any labels for subroutines referenced inside a function, must be created inside the function. You are trying to gosub to a label that exists in the main program outside of the function. The function cannot recognize this.

And in general, if you have huge lists of choices that depend on the value of a single variable, you can use the Select Case command combination. If you use C or C++, it is similar to the switch case combo:



Enjoy your day.
Swampert
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location: Somewhere in the Interwebs
Posted: 26th Nov 2009 23:14
Ah. I'm using DBP. and that doesn't seem to be the problem because Although it doesn't give me whether I win or lose, it does go back to the game subroutine after pressing Y to play again.
Digger412
17
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 27th Nov 2009 00:32 Edited at: 27th Nov 2009 00:32
@Swampert - Hmm...I'm looking at it and I don't know why it wouldn't work. This works, though:

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Nov 2009 00:13
Why are you all using GOSUB as if it were GOTO? Using GOSUB without having an equivalent RETURN statement is worse than GOTO on it's own - you are basically lying to yourself in code.

Also there's no need for this code to have any GOTO in it at all. For example:


Can be rewritten as:


Login to post a reply

Server time is: 2024-09-28 12:17:38
Your offset time is: 2024-09-28 12:17:38