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 Discussion / Sudden program ending bug

Author
Message
Exile1043
17
Years of Service
User Offline
Joined: 24th Mar 2008
Location:
Posted: 24th Mar 2008 22:48
Hi everyone!
my name's quinten, and i've been fiddling around with darkbasic for some time now, never took the time to make a forum post though .

Here's my problem, i've been working on my first game, creating a virus (biological) and evolving it, infecting other cells etc.
it's text based,uses a lot of random numbers and a (5,10) array.
now the problem is, sometimes it just quits the program between an if and a wait key, it doesn't even return an error.
i put a print "whoops, error" and a wait key at the end, which the program shows like normal, so there isn't a "real" error.

here's a code snippet


in this piece of code it usually stops, before the wait key, it just displays the "whoops, error" and the program exits.
the playercombatroll and playercombatmodifier variables weren't there in the first place, it just rolled the random numbers, added the skill modifiers and compared them, resulting in an outcome.
so, does anyone have some advice on how to solve this?
i'd be very gratefull
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Mar 2008 23:35
Quote: "does anyone have some advice on how to solve this"


That snippet isn't enough for us to go on really. But, in short, dump the Goto.

Unstructured programs which jump using Goto are very difficult to maintain and as they are not procedural, can be prone to errors - including just ending suddenly. That's what they do.

What you need to fix the problem can be found in tutorial 2 here:

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

Even if it's not directly the cause, finding it will be much easier...

TDK_Man

Exile1043
17
Years of Service
User Offline
Joined: 24th Mar 2008
Location:
Posted: 24th Mar 2008 23:51
Hey TDK,
thanks for the quick response, i appreciate it.
well, basically not using GOTO means i have to scrap my entire program, or spend hours trying think of and implement another way to do this.

but, you are more experienced, so i'll just go through your tutorials then

thanks a lot!
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Apr 2008 03:44
that's a nice game idea.
if you have to scrap the whole program to eliminate the gotos then do so. you have to be prepared to chuck out old code as you learn, you'll be laughing at this program in 6 months time. and that's because you'll know how to write it better.

you've shown me an application for the weighted random number generator i just wrote (not as complicated as it sounds) so I'll post it up in a minute.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 4th Apr 2008 06:59
Quote: "not using GOTO means i have to scrap my entire program"


That doesn't have to be quite as drastic as it sounds.

After reading the tutorial, you will find a modular skeleton program. All you need to do is start a new project with the skeleton then cut and paste the code from the sections you currently use Goto to jump to in your existing program and paste them into the procedures you rename (or add) in the skeleton.

A minor bit of cleaning up and you are done. Probably shouldn't take you more than 15 minutes to half an hour and you'll end up with a program that will probably work and be infinitely more manageable, efficient and upgradeable.

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Apr 2008 17:22
ok, long minute but here i am

the weight in your program would be the distance between the two cells.
I like this function because the maximum is still possible.

Exile1043
17
Years of Service
User Offline
Joined: 24th Mar 2008
Location:
Posted: 4th Apr 2008 17:35
Thanks again TDK, but i already modified my program using SUBs , and it's working well so far, i managed to remove that sudden exit bug, i think it had something to do with the random numbers, but i'm not sure.

@Obese87
Thanks for the Number generator and the fact that you like my idea . i was afraid i was one of the few that like these kinds of games, maybe i still am... but at least i got more motivation now . this is just a little demo i'm working on by the way, i tried making 3D games before, but i failed miserably, so this time i'm gonna take it slow and try all the code i can in a text based game before trying to go 2D or 3D.

but... i'm afraid i don't know how to use functions yet, so i won't have much use of your number generator for now .
thanks anyway ^^
Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 12th Apr 2008 09:16
I think you will find subs and using gosub a lot better than using goto.

GOTO : a goto will jump the program - forgeting where it was and it does not return to the part of the program that calls it(the caller)


Subs : subs not only execute code, but they return to the caller


functions : functions not only return to the caller , but have the added advantage to return imformation - such as how much the distance is to antoher object.

In most cases , Goto can be substituted with a repeat - until loop or an if-endif statement or a while-endwhile statement. I dont advise that you use the goto if you can find an alternate solution.

Login to post a reply

Server time is: 2025-06-07 17:07:20
Your offset time is: 2025-06-07 17:07:20