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.

AppGameKit Classic Chat / How to do updates, but without sync() pausing everything else? question related to movement to a target

Author
Message
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 5th Nov 2018 18:43
Hi there!

I'm using basically a loop in a function that moves the player by incrementing it's position, until it has reached the target. This works fine, however it requires a 'sync()' to actually show the movement in progress or it'll just skip to the end and only update once then.
Same deal in case I would have used a while loop, like so:



xxx# , yyy# and zzz# are nothing special, just the distance to target in a positive or negative value.

My question is... how do I make an object continue to visibly move until the target, whilst NOT pausing anything else that happens in my game?? I've got a feeling I'm overlooking something really easy bigtime here, to do with general code structure, but can't seem to find the issue.

PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 5th Nov 2018 18:48
I should add that taking out sync() in the While loop freezes the game. Not sure why.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th Nov 2018 19:14
First off ide like to say it looks great

Im not sure how the rest of your code works but if your using physics in other parts of your code
you will also need to update the physics in any other bits of code that loops that you require
physics updates. Step3DPhysicsWorld()
fubar
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 5th Nov 2018 19:50
Thanks! Nah, I'm not using the physics engine for this game. I think the issue has to do with how my main game loop is set up somehow. However, the strange thing is that many other things do continue to update.
I think I have to restructure my code. Many people use code where the main Do Loop has little more but a game state controller and an update function of sorts.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th Nov 2018 20:28 Edited at: 5th Nov 2018 20:29
Oh that's much harder but still doable

You need to write the routines that need to be updating so as they work in parts

ie movethingy 1 pixel
move something else 1 pixel
etc

then you would call your update function

the update function might be something like this and return if your ready for next turn or not

something like this logically
create function updatefuncion()
exitstatus=0
a=movethingy()
b=movesomethingelse()
if a=1 and b= 1 then exitstatus=1 //meaning that they have both completed the maximum movements of each
endfunction exitstatus

you would call your updatefunction in your loop
fubar
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 5th Nov 2018 20:31 Edited at: 5th Nov 2018 20:32
If you remove the sync() and haven't put anything else in to render then probably the game is not frozen and instead is just not updating the screen. Are you using the Render functions in place of sync() ? Also a call to update might be needed for reading input devices playing music etc.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 5th Nov 2018 20:40
yes you should ideally only have 1 sync per frame.
better to reorganise your code to disable input while the movement is happening (perhaps use the targetreach variable to do so).
i.e.
if targetreach = 0
//player input code goes here
//if player makes a valid move set targetreach = 1
elseif targetreach = 1
//do movement code here
//once reached the destination set targetreach = 0
endif
sync()

as for it freezing if you remove the sync in your loop, that's probably because it's running at a much faster rate and the calculation for checking it's at an exact location (i.e. if GetObjectx(objplayer) = target_posx# and GetObjecty(objplayer) = target_posy# and GetObjectz(objplayer) = target_posz#) is a bit too exact and it over shot the target - probably want to check it gets within a small distance and then teleport to the exact location (it should be so small you won't even notice).
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th Nov 2018 20:59 Edited at: 5th Nov 2018 21:08
There's a thing called a Single State Machine. It sounds very scientific and all but it's a very simple concept; Something can be in only one state at a time.
So in relation to a game it's a bit like this.

GameLoop
- select GameMode
-----SplashScreen
----------do stuff
-----Credits
----------do stuff
-----GamePlay
----------do stuff
- endselect
endloop

It's the same for everything;
Player
-select PlayerMode
-----MoveToTarget
----------DoOneStep
-----RunAway
----------DoOneStep
-----WanderAround
----------DoOneStep
-endselect
endloop


Once you start thinking this way everything will become really easy and simple to manage.
You will find your no longer trying to juggle a million things.
Hope this helps
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 5th Nov 2018 21:42
Thanks, very useful tips indeed. Yeah my coding is very chaotic (it's just the way I am lol), but it does seem like I have to restructure the code to get past this issue.

I have a Sync() in my main loop and kind of feel that should really be the only one. However, some functions do have their own loops that need to do something during a turn. The two main states my game has for it's gameplay are essentially either the player turn state or enemy turn state. Along with that, the main loop continues to update things. I guess this doesn't work quite as it should at the moment.

Small update with some rough animations for walking done. It's not that the movement doesn't work, I just don't like how it pauses the potions rotations and water texture scrolling for a bit.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th Nov 2018 21:59
Quote: "There's a thing called a Single State Machine. "


Oh yes I forgot about those myself and I think from memory there is a turing machine which is great for testing logic
plenty of java turing machines avaailable
fubar
puzzler2018
User Banned
Posted: 5th Nov 2018 22:01 Edited at: 5th Nov 2018 22:11
You can have many syncs in different ways - but are they effective...

Do

Sync3dStepPhysics // if you need them
Sync()
Loop

Please do not use Goto or GoSubs to go between individual sync loops - but destroy a frame loop will upset your syncs

Some good advise above

and always try to always 1 sync in the whole code and use different states like said above

- If game is in pause mode - then have this as the first IF statement in the DO LOOP and all your game routines are within this pause IF statement else show a Pause icon. but still indeed have the main sync() at end of the main loop to indeed show a pause banner!!


The pause for apps i feel requires to be implemented in most apps - toilet duties

Login to post a reply

Server time is: 2024-03-28 15:44:18
Your offset time is: 2024-03-28 15:44:18