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 / GOTO and GOSUB problems.

Author
Message
squids
21
Years of Service
User Offline
Joined: 1st May 2003
Location: United Kingdom
Posted: 10th Jun 2003 00:45
Hey,

I have been using the following code to try and restart my cruddy game im making;

if clicked(166,160,266,180)=1 : goto _jump : EXIT : endif
if clicked(371,160,471,180)=1 : playFlag=0 : EXIT : endif

I have been using both GODUB and GOTO but I cant quite seem to get it to work the way I want. Basically as this is my first game and im new to DB/P, my code is somewhat erh linear. I have a severe lack of functions etc,. I am not sure if this is a hige problem or not.

What I was hoping was, when the first area was clicked I could send the program back to the start of my code and have it run through again,. and if the other area is clicked then it will exit. The program quits okay but I cant get it to start from the top of my code again. The only thing that happens at the moment is that when you click the restart game area, it jumps to the code at the beginning does the first loop there and then comes back to the restart/quit screen again. Is there any way I can make the program jump to the top and work its way back through without returning?

Many Thanks,

Ash.
.Arf..
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 10th Jun 2003 02:54
i think it should be coded like this:

if clicked(166,160,266,180)=1 then goto _jump
if clicked(371,160,471,180)=1 then playFlag=0 : EXIT

be aware that jumping back to the start of the code without re initializing your variables may leave unwanted values in them.
squids
21
Years of Service
User Offline
Joined: 1st May 2003
Location: United Kingdom
Posted: 10th Jun 2003 03:20
Hey,

Tried that and it didnt work, however,. I managed to get the goto working via adding "wait 50" in my code,. seems to have needed to slow down a touch,. oh well,. im confused,...

.Arf..
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 10th Jun 2003 13:45 Edited at: 10th Jun 2003 13:46
nothing unusual there, DB has this weird thing where sometimes the screen doesn`t get updated or an instruction gets skipped, or (realy weird) performed out of sequence, not everyone seems to to get this though, sometimes you need a double sync after print

print "press any key to start"
sync
sync

or the message is not displayed, and sometimes it just seems to ignore a instruction and you need a wait to get it to read it, and that slows everthing down so you are forced to rewrite the code

position object 10,10,10,10
wait 50
if b=9 and cartridges=0 then noreload=1
sync
loop

and sometimes it screws up your code by doing two instructions out of order but I don`t know of a quick fix for that other than rewriting the code, and sometimes the editor refuses to recognise valid syntax for reasons unknown, all these bugs are (I hope) being worked on and a new version of the editor is up and coming, there are some bugs in some of the functions and commands too.
also it is generaly considered better not to use goto because you can get your code realy messy and unstructured, although I would use it to loop to the top of a simple program like you mention, and it is possible to use goto to make your code faster or simpler, but generaly goto is frowned upon, cheers.

Mentor.

squids
21
Years of Service
User Offline
Joined: 1st May 2003
Location: United Kingdom
Posted: 11th Jun 2003 03:28
Thanks Mentor,

Now I will have some idea what to change and things to look for when I experience similar problems.

Thanks,
Ash.

.Arf..
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 11th Jun 2003 19:54
Here is a good advice:

Quote: "Do not ever use the GOTO command"


I think it was the 11th commandment!

Why you may ask:

You have two options to control the flow of your program, both in a very controled (sic) way.

Gosubs which is a call from Subroutines and Function calls which is used for Functions, no surprice there then.

GOTOs fall into neither of those two categories.

I tend to imagine a program as a flow, a nice circuit of a well-tempered instrument. Gosub and Function calls divert the flow through your circuit but never interupt it, or at least never should.

The GOTO stops what's going on till you hit it and 'teleports' you without any control or flow to some other part of the code. It is a disaster waitting to happen. It is a hicup in the code... Once you start using the GOTO it means that you have not though the consiquences, the return, of this action!



-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy

Login to post a reply

Server time is: 2024-09-20 12:35:59
Your offset time is: 2024-09-20 12:35:59