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 AppGameKit Corner / Help with restarting a Level

Author
Message
Sh4d0xx
9
Years of Service
User Offline
Joined: 5th Dec 2014
Location: United Kingdom
Posted: 16th Jun 2016 14:56
Hello AGKers,

I need some help with a little game I'm making.

So far everything else works fine, but I'm stuck with a way to restart a Level if a certain condition isn't met.

I used the 'Baws' game demo as a backbone for structuring my code, which means it relies on 'Gosubs'.

I can progress through the instructions screen, level 1 and 2 in a linear fashion with no issues whatsoever, however if the conditions for level 1 aren't met, a little interactive sprite pops up, and the end user is meant to click on the sprite and replay the first level.

I've tried quite a few solutions, and the best I've been able to do is go back to the instruction screen. However the moment I decide to proceed from the instruction screen to 'Level 1:' all I get is a blank screen with the timer still running from the last attempt.

Does anyone have any suggestions for how to branch away from the linear fashion of the Gosubs ?

Thanks.
Shadow Props Digital
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 16th Jun 2016 15:52 Edited at: 16th Jun 2016 15:52
Quote: "which means it relies on 'Gosubs'
"


uh, this will be more tricky, next time you have to rely on functions instead of gosubs, it's way better and cleaner.

If you use gosubs, and want to restart your level, you may have to reset all variables in your level code.
You may also have to delete the created media once you finish the level. I really don't know, this is based on your structure inside the gosubs.

Quote: "all I get is a blank screen with the timer still running from the last attempt
"


try to reset everything you find.

Greetings, Jack

[/url]
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 17th Jun 2016 19:10 Edited at: 17th Jun 2016 19:10
They really should remove gosub from AGK. It's evil.

Anyway, wrap it all in functions. I helped out another guy here who also used gosubs and had a similar problem - step by step and ending up with full code done using functions to solve all the problems of his initial code.

Link to it here

Read it through, and for your next project, just pretend the gosub command (and global variables) do not exist.
Sh4d0xx
9
Years of Service
User Offline
Joined: 5th Dec 2014
Location: United Kingdom
Posted: 18th Jun 2016 22:10
Hello Guys!

Thanks for your valuable input.

Sorry for the late reply, I've had a very busy desk.

Quote: "you may have to reset all variables in your level code."


This is something I will be experimenting with tonight.

Quote: "You may also have to delete the created media once you finish the level. "



I have implemented this method, but it fails me till this very moment

Quote: "Anyway, wrap it all in functions."


This is something I am willing to try this weekend. I will read your tutorial and get back shortly.
Shadow Props Digital
Sh4d0xx
9
Years of Service
User Offline
Joined: 5th Dec 2014
Location: United Kingdom
Posted: 18th Jun 2016 22:19
Quote: "Read it through, and for your next project, just pretend the gosub command (and global variables) do not exist."



Hello,

Considering the volume of code I've written, would the best way forward be to remove the gosubs and replace then with functions ?

e.g.

function Stage1()
endfunction

function Stage2()
endfunction

And I am guessing I can call one function from another ?

e.g Calling Stage 2 from Stage 1 ?

Many Thanks
Shadow Props Digital
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 19th Jun 2016 14:50
Yes. Where you've used labels and return, wrap it up within functions instead. And rather than call a specific part of your code using gosub and label, just call the function instead.

A function is basically a user made command. Use it like any other command. Read through the link I gave, and by the time you reach the end, you'll have a good grasp on just how versatile functions can be.

If it helps, from the link I gave, print out the OPs original code and then print out the final code in my last post there. Compare the two and notice the differences in program flow and structure.
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 23rd Jul 2016 21:01
Always use functions, unless you have to make ALOT of calls REALLY REALLY FAST, like multiplying two values a million times.
In that case, use gosubs.


Login to post a reply

Server time is: 2024-11-22 04:00:44
Your offset time is: 2024-11-22 04:00:44