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 / Resetting evrything?

Author
Message
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 28th Feb 2012 17:55
Hi evryone

I have a small problem with my game, when I play the game, then return to the menu and try to play again, the game crashes without any kind of error message. Im guessing it's because of what I do to reset the game when I return to the menu.

There is allso a problem with variables keeping there value when I "reset" the game wich I would like to get rid of. There fore Im wondering if there is a way to reset evryting, setting all variables to 0, removing all media ect. Is there any command that does that?
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 28th Feb 2012 22:05
Do you move to the menu of your game? Or the device menu?

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 28th Feb 2012 22:20
The menu of my game
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2012 22:26 Edited at: 28th Feb 2012 22:27
I'm afraid there's no easy way to reset all the variables in your game. You need to consider this as you build your game up. I tend to have an "init" sub-routine which resets everything before setting up a new game. It's more or less my initial set up code but without any media loading or setting up of UDT's, globals, constants or arrays.

My structure (when I stick to it) is more or less like this:


The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 28th Feb 2012 22:49 Edited at: 28th Feb 2012 23:00
That's what I assumed. I'll have to try to find the crash bug then...

Edit

I have a theory about why the game crashes. I reset evrything, eccept the variables. Wich means I don't reset the arrays. then when the game is run the second time, I use the dim command again.

Could that cause a crash and if so, how do I prevent it? Can I delete an array?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2012 23:28
Using the dim command again does not delete the data in the array. You need to manually reset that too.

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 29th Feb 2012 08:16
That"s good news, What about types. Could they cause a crash if they are created twice?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Feb 2012 10:06
Yes you can't create two UDT's with the same name. It might not crash AppGameKit on any platform but I wouldn't run the risk.

bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 29th Feb 2012 13:35
I keep type declarations in a seperate area from variable declarations.

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 29th Feb 2012 20:06
Do a check in your setup if the array exists, then just alter the values back to 0 or whatever the default is. If not then create the array and then alter the values. You are very likely to cause bad crashes in AppGameKit if you try to create an array that already exists. I tend to use a setup routine which I run before each game start and between levels. Although I tend to declare array dimensions at the very start and only alter the contents in game, not the actual array structure.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Mar 2012 19:57 Edited at: 1st Mar 2012 20:01
I have developed a "system" for my projects which uses two functions.

InitVars() is called once at the start of the program, this includes setup code for display, media loading etc. It defines arrays and globals but does not populate them, it then calls the second function;

ResetVars() is used to set everything to its initial state, including populating of arrays and global variables. It sets the program state to "menu".

The general program outline is;


For larger projects which use include files for common code, these also have their own InitVars() and ResetVars() functions;



Its a bit more work to set up, but it keeps everything modular.
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 2nd Mar 2012 08:27
Thanks for the replies

But my main problem is not that I want to reset my variables. It's the fact that my game crashes when I retrun to my menu and then try to play it again

I allso tried an old version of the android game laying around, and in that version the game didn't crash the first time I played. But It created some bugged white sprites and it got worse each time I restarted until it crashed after about 5 restarts...

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2012 09:14
Your first post does suggest that not resetting variables correctly is the cause of the problem. Perhaps if you explain how the problem manifests itself then we can point you in the right direction?

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 2nd Mar 2012 18:18
The part about the reseting variables thing was a theory... And still is

Anyway the problem im experiencing is that When I start the game, the game sets the resolution and #includes all files, then go to the main menu. When there you press play game and the game runs fine. But if you return to the menu after playng and loading evrything, the game deletes all Media used



The menu is fine, but if you press play game again the game crashes imedietly, without an error or anything, the game shuts down.

The fact that I delete evrything when going back to the menu makes me believe that media loaded twice is not the issue. But what I don't do is reset all variables, Removing arays and types or anything like that. Wich Is what I believe is causing a crash.

I did a test though in wich I created both an array and a type inside a loop and it didn't crash.

Allso, on an older version of the game that I had on my android phone, the crash didn't happen untill restarting about 7 times. The game did however create some random "dummy sprites (white boxes)".
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2012 22:03
Do you dim your arrays in the main agc before your loop (not in a sub routine or function)?

If not that could cause problems sometimes...

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 3rd Mar 2012 10:09
I do dim a few arrays in subroutines, i'll try and move them when I get time today...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Mar 2012 12:11
That will certainly help.

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 4th Mar 2012 20:30
I finaly got around to moving the Types and Subs to my main .agc

But it didn't help.

I allso showed the game to a friend and on his computer the game didn't crash evry time.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Mar 2012 21:40
Well, maybe you could share some more code? It's just guesswork really otherwise and could take a year to debug without looking at any actual code.

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 5th Mar 2012 15:14
Well, since I have no indication of what's causing the issue, I would have to share the whole code, right? I'll will attatch the code to this post and remove it in a few days, just in case
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Mar 2012 15:24 Edited at: 5th Mar 2012 15:33
I'll take a look Zoq2...

EDIT: Straight away I see a stack overflow problem. You're using a "goto" within your Menu loop that leads outside the loop (or to a new instance of the current loop). This will eventually kill any application. Never ever ever use a goto that leads outside your current loop. If in doubt just don't use goto at all.

The "Weapons.agc" file is not included so I can't compile it even if I remove all references to images.

You've no reason to trust me but if you email me the full project I will debug it for you and find out what is causing the issue.

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 5th Mar 2012 19:49
Quote: "You've no reason to trust me"


I have no reason not to either

Ill send the files right now.

Login to post a reply

Server time is: 2024-11-23 05:12:45
Your offset time is: 2024-11-23 05:12:45