|
-
Trainee coder
[RESOLVED] [HELP][URGENT] Updating Var's
Ok, basically if anyone can help me within 1 hour of posting this, then I'll be super happy, otherwise it'll be too late but still thankful for a solution anyway.
Heres my problem: in my game I've got 3 keyframes (menu, game, end), when you die you are brought to the 3rd frame and then diverted back to the main menu (first frame). When 'restarting' the game I just tell the main playhead to move back to the 2nd frame (game frame) and I'm assuming everying should be initiated the same as if you're moving to it for the first time. This cant be the case, becuase my key and mouse listeners arent working, and I'm pretty sure some of the on-screen assets have occassionally disapeared.
Sorry, I cant post the source or anything (I know that would be helpful), so if anyone has any huntches at all, I'm all ears.
Viza.
[EDIT]: RESOLVED! believe it or not, but evry time I post something here, I grow a brain
Last edited by Viza; 10-01-2007 at 10:57 PM.
Reason: RESOLVED!
-
Pumpkin Carving 2008
And the solution was? It might be helpful to post this for the rare occasion someone should use the search feature.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Trainee coder
I was adding 2 listeners (keyboardd, and mouse) on frame 2, without removing them. I'm guessing flash deleted the new object listeners but never replaced them (unless they weren't already present, hence why every 'even numbered' restart would work) when coming back to frame 2??
Viza.
-
Pumpkin Carving 2008
Are coding on the root? I usually put all variable declarations into a function like initialize() without the keyword "var." This will still make their scope the _root. Then anytime you need to start over, just call the function again and it will overwrite all the variables with their defaults.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Trainee coder
Yeah, I'm coding on the _root. The initialize function is not a bad idea (I just didn't think I would have that problem; anyway, I just had to include two extra lines of code).
What I have noticed from this latest project is that I need to use functions a lot more: I use them everywhere in OOP stuff and classes (obviously), but when I'm lazy I tend to just place bits of code around only to find at the end of the project that if I had made it into a function I could've saved a few hours of searching and adjusting the same repeated peice of code.
Viza.
-
Pumpkin Carving 2008
Yeah I used to do that too. Last month I finally started getting the hang of AS classes, and now, despite what anyone says, I find myself coding everything into a class now... but clearing up repetitious chunks of code and writing a function is a good idea; it's called modularity.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Hype over content...
I know this is done, but one quick point.
If you create vars without using the var command, it can lead to memory leaks. So rather than having an init function with the "global" vars defined in it without using var, just have a separate layer and define them all there once.
Then your init function can shove the default values in there, same end result, but no leaks and you have a layer called vars in which to look for everything to ensure it's defined.
Squize.
-
Senior Member
IP, I like the initialize function idea. I will have to assimilate that. I was in the habit of declaring vars where they were going to be used for the first time, which makes sense for a small project, but this one isn't really small, and it led to variable declarations all over the place.
Squize, also a great idea. Definately going to use both of these. It will also have the benefit of making it super easy to find my variable names at a glance. I always forget my _root level variable names.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|