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 / Running infinite loop within mainloop

Author
Message
Thomy100
7
Years of Service
User Offline
Joined: 29th Oct 2016
Location:
Posted: 29th Oct 2016 23:32
Hi, I am pretty new to AGK2 and programming in general but managed so far to program a "chase-game" where a guy collects coins while an enemy is trying to catch him

To juice the whole thing up, I want to add barriers after a certain score level and even further barriers which move from left to right and back.

The problem now is, I managed to code a barrier that shifts back and forth within a for loop but since this back and forth movement shall be infinete (as long as the game is running) it get's stuck in this for loop. So I need a way to start an infinite loop within the main loop. Is that even possible? I read about multithreading and stuff but this kind of skills are still lightyears away for me.

Would appreciate any help. Thanks in advance!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Oct 2016 08:51 Edited at: 30th Oct 2016 08:51
Welcome to the forums.
To make sure your posts are seen, you should post in AppGameKit Chat or AppGameKit Newcomers corner. This board is for mainly DarkBASIC (and was created before AppGameKit existed).
I will move the post in a while, but leave it here for the time being so you don't lose track of it.
Let us know if you are using Tier 1 (Basic) or Tier 2 (C++)

Firstly, you can't multi-thread AppGameKit, it is not thread-safe. Internally it is doing weird and wonderful things, but at the level we interact with it, it is not possible.
You only need one main loop that cycles eternally. Beyond that, think about turning switches on and off. Your switches are variables with a value of 0 and 1 (at the simplest level). In Pseudo code you can now switch on your barriers after a set time and enable their movement...




Here, the barrier is switched on once the time reaches 10 seconds
Once the switch is set to 1, the chunk of code that moves the barrier is allowed to run in each cycle.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Thomy100
7
Years of Service
User Offline
Joined: 29th Oct 2016
Location:
Posted: 30th Oct 2016 18:31
Thanks a lot BatVink

Sorry for posting on the wrong thread, will be more careful in the future
Thomy100
7
Years of Service
User Offline
Joined: 29th Oct 2016
Location:
Posted: 30th Oct 2016 19:39
Thanks for your Reply BatVink.

I tried what you suggested with the switch but I seem to do something wrong. I post my code so someone can maybe point me into the right direction. The problem is, as soon as the barrier movement starts by using a for loop (back and forth), the program gets stuck in that loop



Maybe I didnt use Switch correctly?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Oct 2016 20:29 Edited at: 30th Oct 2016 20:30
You are still running an inner loop that processes the entire movement. The idea is to use only the outer loop and move the barrier one increment each time. Something a little more like this:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Thomy100
7
Years of Service
User Offline
Joined: 29th Oct 2016
Location:
Posted: 31st Oct 2016 21:30
yeah, I see now what you mean... got it, thanks a lot

Login to post a reply

Server time is: 2024-04-23 23:39:36
Your offset time is: 2024-04-23 23:39:36