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 / Can Anybody help me?

Author
Message
GLaDOS
15
Years of Service
User Offline
Joined: 16th Jul 2009
Location: Italy
Posted: 22nd Dec 2012 19:42 Edited at: 22nd Dec 2012 19:46
Hello! Im writting a simple game where there are 6 holes and in one of them there is a "trasure".it worked well,but it was a little buggy as there was no way to "respawn" after you loose so i made one,and after that it wont work well.only the first hole work,the other one are just black
(hold on while i try to figure how to put the code in the code function)

I know its not english,its italian,And just ignore it,its print,Nothing about the problem i have
The hole 4 is the one with the treasure,while the other ones are jsut nothing

~GLaDOS
sayerbloke
11
Years of Service
User Offline
Joined: 1st Dec 2012
Location:
Posted: 22nd Dec 2012 20:09
I'm a still new to the forum so apologies all around if my reply is authorised after someone else replies!

I'm not on my machine with DBPro installed to test your code, but a quick look suggests changing each check to something more like this would be the key:

If I$="1"
Print "Non C'è Niente "
Wait key
Gosub Respawn:
endif

i.e. using endif and capitalising the 'R" in Respawn. There are other ways of writing the code altogether, but that should fix the basic issues.
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 22nd Dec 2012 22:20
Hi GLaDOS

I can see that you're getting into a bit of mess and judging by your other post you seem to have confused how GOTO and GOSUB work. GOTO allows you to skip chunks of code where as GOSUB needs to work in conjunction with RETURN, which will take the program back to the line after the GOSUB was called when the programming is running.

In order to get "respawn" or "play again" to work properly you need to wrap the game play portion of the code in some kind of loop. By way of example (I did this for someone else on the forum so it's not specific to your problem):



The important thing to note here is not what all the lines of code are doing but how the program as a whole is structured, how the sub-routines have a RETURN command at the end of them (unlike a label that would be used for a GOTO). This is just an example and by no means the only or best way of structuring your code.

So, ignoring all the remalks at the start, the first line (line 7) of the program is:

gosub GENERAL_SETUP

this means that the program now jumps to the GENERAL_SETUP: label (line 28). A bunch of code is then executed and then the program hits a RETURN command (line 38), which takes the program back to line 8 (which happens to be another GOSUB command.

The sub-routines are really just giving the code a a more organised structured, it could all be done without sub-routines or could be done using functions.

Specifically to your code, is could be written like this:



What I've done here is wrap your entire code in a DO...LOOP. The way I've structured it, the "Respawn" sub-routine can be thought of as a "initiate game" sub-routine". However, this might not suit a game where the number of guessing is counted and, on a replay, the number of guesses would be set to zero again.

Hope this helps.
GLaDOS
15
Years of Service
User Offline
Joined: 16th Jul 2009
Location: Italy
Posted: 22nd Dec 2012 23:05
Thank you,i got confused by a tutorial about not using GOTO,Thanks alot

~GLaDOS

Login to post a reply

Server time is: 2024-11-24 07:04:13
Your offset time is: 2024-11-24 07:04:13