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 / While loop inside Do loop doing some weird business

Author
Message
Divided
FPSC Reloaded TGC Backer
11
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 2nd Aug 2016 04:11
I'm developing a game that requires physics and shapes for iOS blah blah blah etc...

I created a basic timer visualization shown here:


Seems to work how I want it to, that is until I discovered that one of my other functions is hindering it's ability to move when active.
This function here:



Basically the function will draw a black line vertically down the screen from wherever the user has touched to indicate where the shape should land.
Now, in doing so commands such as Print( "Blah Blah Blah" ) disappear temporarily until the function has ended and the code moves on from the loop.
Also, which brings me to the main issue that the size of my timer stops decreasing as well when this happens and when the loop is broken, it
continues from where it should be.

Why is this happening?
How do I stop it?

I know it has something to do with the loop and the Sync() command.

An alternative i've tried was to make it an if statement instead of a loop but then I was presented with a whole host of other problems I don't want to deal with.

Thanks in advance!
Real programmers don't comment their code, because if it was hard to write it must be hard to read!

- PixHil Entertainment
Download Pixel Smasher on the App Store today!
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 2nd Aug 2016 05:55
Hmmm, I have a few questions before I can help you.

1) Are you using gosubs? If so, get rid of them. Just my opinion, they tend to make things more confusing in the long run.
2) What's the point of this: shape as Shapes[] in your functions, as you don't actually use them in your function?
3) Instead of using the print command, create a text object. This will make it much more easier to manipulate in-game.
4) Where do you call your functions in your game loop and do you have sync() at the end of the loop?

When you only post parts of your code, it makes it very difficult to debug. Try to post as much code as possible pertaining to your problem, including the main game loop. You never know, it may be something simple as a command error outside the function that's causing the issues.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Aug 2016 07:25
I think there are 2 parts to your issue:

ResetTimer()

and the Sync() in your TouchLine() function, which is the main problem.

ResetTimer() will play havok with anything timer based. It is only intended for use when your app is running for hours at a time, and you require high precision timing.
Over a few minutes, it is not required.

Sync() should ideally only happen in your main program loop. In your scenario, the program stays in the TouchLine() function while the mouse button is pressed. At this point, everything else is on hold until you release the mouse button.
You should repeatedly call TouchLine() from the main program loop, thus continuing to run your timer display code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Divided
FPSC Reloaded TGC Backer
11
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 5th Aug 2016 05:14
Thanks for your responses!

Quote: "
Are you using gosubs? If so, get rid of them.
"


Done. I still use some for loading sprites and media in separate files, it's just more convenient. All logic is done through functions though

Quote: "
ResetTimer()

and the Sync() in your TouchLine() function, which is the main problem.
"


I don't quite understand what you mean here. I only call ResetTimer() as a means to reset the game's timing function which when it ends, the game basically resets. It's not a part of the looping problem i'm fairly sure.

Anyway, I'm still having significant issues solving this one. I tried removing the while loop in replacement of an if statement but I keep getting odd things happening which I don't want. However in switching to an if statement in place of while, it does fix my resizing issue.

Here is a look at the main loop and timer code:


Few more timer function from other file:



And finally a look at the main issue which is while the user holds a mouse button down:



I appreciate any help on the matter.

Cheers!
Real programmers don't comment their code, because if it was hard to write it must be hard to read!

- PixHil Entertainment
Download Pixel Smasher on the App Store today!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Aug 2016 08:43
Quote: ". I still use some for loading sprites and media in separate files, it's just more convenient."

No, it really isn't!
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 5th Aug 2016 09:42 Edited at: 5th Aug 2016 09:47
Quote: "No, it really isn't!"

Bit harsh. My suggestion, turn sprite and image load/creations into functions also. Cut down your code and makes it easier to read.

As for the ResetTimer() bit, you really need to work around that and find a way to not do that. If your program starts to get bigger, you may end up causing a lot of headaches in the long run. So one way is to change these lines to this:


That way you can get rid of your ResetTimer() bit and than you can add as many Time based conditions as you want without worrying about mucking everything up in the long run.

As for the mouse input, first you need to setup a variable that tracks the state of input, this will allow you to do what you want to do when you press, hold and release based on the current state of the mouse. Also, turning physics on and off all the time, especially with that function that doesn't check for input state, is going to create a huge mass amount of headaches, which it would seem you have. Instead, just pause the physics engine, which will make it much much easier. Here's a quick example for input states, you'll have to build your own using this template:



One last thing! Take out your input check and put your sprite function inside of it, not the other way around like the way you have it now. Another thing that will give you headaches in the long run, and currently, lol.

Good luck!
Divided
FPSC Reloaded TGC Backer
11
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 5th Aug 2016 13:44
Quote: " No, it really isn't! "

Well for my purpose I personally find it convenient and honestly can't be asked to change it now.
Quote: " hat way you can get rid of your ResetTimer() bit and than you can add as many Time based conditions as you want without worrying about mucking everything up in the long run. "

Cheers! Very insightful.

I've managed to rid myself of the problem. Probably not in the most efficient way but it works so i'm happy.

I've taken a sightly different approach than your suggested inputstates.

I've moved the Timer code out of the main loop into a function which I than call throughout the main loop and inside the while loop.
this appears to have completely solved my issue.

Is there a way to efficiently lower function parameters. I find myself with functions that require lots of parameters which bugs me a little.

for example:

MyFunction( abc, def, ghi, jkl, mno, pqr, stu, vwx, yz )
Real programmers don't comment their code, because if it was hard to write it must be hard to read!

- PixHil Entertainment
Download Pixel Smasher on the App Store today!
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 5th Aug 2016 14:49
Quote: "Well for my purpose I personally find it convenient and honestly can't be asked to change it now."

Any chance you can show us? Maybe I can show you an easy way to get rid of it and make it way more readable.

Quote: "I've managed to rid myself of the problem. Probably not in the most efficient way but it works so i'm happy."

Can we also see what you did here? It's better to squash bad programming habits now before they become a bad programming habit lol. Trust me! It's hard to break once you've started doing it so much, even if only once which is once too many.

I personally create type 'objects', this way I can assign variables to 'objects' and than when I call a function it just grabs the info from the object array. Here's a quick example:



Good luck!
Divided
FPSC Reloaded TGC Backer
11
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 5th Aug 2016 15:33
Quote: "Any chance you can show us?"


It's lengthy as but here it is.





As for your second question:




And finally, here is where I put my GetTimer() function:



Quote: " I personally create type 'objects' "


That's incredibly helpful, I'm use to C# and creating objects. The agk language makes it way too easy to collect bad habits.
Real programmers don't comment their code, because if it was hard to write it must be hard to read!

- PixHil Entertainment
Download Pixel Smasher on the App Store today!

Login to post a reply

Server time is: 2024-11-17 10:08:12
Your offset time is: 2024-11-17 10:08:12