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 / Dice Roller

Author
Message
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 8th Mar 2008 14:19
Doing a dice rolling game have the basic functions of rolling the dice and before i put in the If I$="N" pressing Y would generate a rolled number, any ideas why it exits the program when i press Y now?



Thanks for any replies

Zen

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 8th Mar 2008 15:37 Edited at: 8th Mar 2008 15:41
1.) Ahhhg!!!! It's a goto!! Quick, get rid of it before TDK sees!
Seriously though, gosub is faster and better than goto. The only reason they kept goto around was for compatability with older projects where they didn't have gosubs.

2.) You don't need to put colons after every if statement...the only time you need a colon is if you are putting multiple commands on one line. Or if you are declaring a subroutine.

That's weird, though, I can't figure out why it crashes...

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 8th Mar 2008 15:44
Ah, I found it! It's because you put all your endifs at the very end. Basically, it wasn't even checking for a press of Y unless you pressed N! Then it was skipping over the rest because you hadn't pressed Y. Hard to explain, but just look at the new code.

Your code should look like this:


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Mar 2008 16:52
GOTO and GOSUB are not equivalent and one can't replace the other. You should also make sure that every GOSUB has an equivalent RETURN statement somewhere.

Anyhow, I've removed all GOTO/GOSUB commands from the code - they just aren't necessary for this code:


You could go further and put the common code into a function too, but I'll leave that for now.

Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 8th Mar 2008 18:17
Thanks Guys!!! Got it all running, re read up on If statements to make sure i get em!!

Im know this is poor layout etc... but it just helps me get to grips with it this is my first code so here we go after fixing it up we have




It all works but for some strange reason this



Still shows up as Unlucky Commnecing Next Round when getting a lower number than player one

Please help
Thanks
Zen

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Mar 2008 18:43
IanM showed you how to do it properly, so why have you reverted back to that spaghetti code mess using Goto?

I suggest that the majority of your current problems are down to this and unless you learn how to write your programs procedurally, the problems will only increase in the future.

Once again I suggest you read tutorials 1 to 4 here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

And bmaczero explained about the colons - but they are still there!

In your last thread I told you that you shouldn't put semicolons on the end of every line and to read some beginners tutorials. Now your code has colons on the end of lines and as that's not in any of the tutorials I suggested you read, I have to assume that you didn't bother reading them.

If you ask questions then completely ignore our advice then don't be surprised if in the future no-one bothers to answer them.

TDK_Man

Login to post a reply

Server time is: 2024-09-27 12:14:31
Your offset time is: 2024-09-27 12:14:31