Forums

annoying variables problem


Subscribe to annoying variables problem 10 posts, 4 voices

 

Jul 30, 2008 3:57pm

I Break Things I Break T... 160 posts

OK, so, here's my latest error.

"unknown variable"

the player object has two sprites (to simplify things). Sprites 1 and 2. When I press a key, it checks if sprite 1 exists, and if it does not, the object may become sprite 2. Because I use sprite_add, the sprites are saved as Global vars. I also erase the sprites I am NOT using every step. SO, when it asks about that sprite, it doesn't exist in any form, and the variable name has no number attached to it, making it an "unknown variable." How do I get around this?

Again, thanks. My stress might just cause my head to explode. I'll upload a video if that happens.

 

Jul 30, 2008 5:22pm

drizzt7 drizzt7 4170 posts

maybe you can assign a blank sprite to it... I don't really understand the problem :P

Work in progress:

 

Jul 30, 2008 6:57pm

Human Road Human Road 64 posts

Use only one global variable global.sprite. When the game starts, set it to sprite1 and when you press the key, delete sprite1 and set global.sprite to sprite2.

Hope this helps.

 

Jul 30, 2008 7:17pm

tdub311 tdub311 1244 posts

go to gobal game settings
click the errors tab
and click "Treat uninitialized variables as 0"

 

Jul 30, 2008 8:05pm

drizzt7 drizzt7 4170 posts

When you delete the sprite, set the variable to -1

I think that will work.

Work in progress:

 

Jul 31, 2008 4:02pm

I Break Things I Break T... 160 posts

I used the tdub solution, which got me over hurdle one and exposed hurdle two...

HURDLE 2:
Trying to delete non-existing sprite.

if blahblah=true and sprite_exists(blahblahblah)
{kill it}

Well, it now recognized the sprite as 0, so it still tries to kill it. Now what oh merciful gods of programming?

"When life gives you lemons, take them and run."
--me

 

Jul 31, 2008 4:06pm

drizzt7 drizzt7 4170 posts

Try setting the variable to -1 when you kill it. I think that will solve both problems...

Work in progress:

 

Jul 31, 2008 4:20pm

I Break Things I Break T... 160 posts

that MIGHT work, but I think that Human Road had a more memory efficient method. Then I'l only need to load, which save scripts and variables!

Well, thank you all for the help so far. If i eventually get this thing to work, I'll delete this thread.

Also, cool dinosaur.

EDIT
Can't use human road's because I have to check if the sprite isn't another sprite. Now for the -1 solution. I probably should have used it first XD

"When life gives you lemons, take them and run."
--me

 

Jul 31, 2008 4:32pm

drizzt7 drizzt7 4170 posts

lol I remember Nailog saying that -1 meant "invalid resource" or something, so that's why I brought it up.

Work in progress:

 

Aug 1, 2008 2:50am

I Break Things I Break T... 160 posts

-1 wont work either.

Let's keep in mind all of the factors:
I am trying to speed up the game
Trying to cut down on memory
-1 for some reason makes the variable still non-existent
I have to check WHAT the sprite is and is not for an object
sprites have to be deleted when not in use, and reloaded when needed

I'll check the 0 idea. Currently, I am ready and willing to GIVE UP!! (go back to internal sprites)

EDIT
here's the error:
In script playerstep:
Error in code at line 13:
if (keyboard_check_pressed(vk_space))=false and (keyboard_check(vk_down))=true and (keyboard_check(vk_left))=false and (keyboard_check(vk_right))=false and strikel=-1 and striker=-1

at position 158: Unknown variable strikel
I didn't save any of that code, which angers me. I didn't save it because of frustration! Gahds!

EDIT EDIT
I don't create my sprites in the beginning of the game. I'm re-trying sprite add to re-look at the error.

EDIT EDIT EDIT
OK, this seems absolutely ridiculous I ask if a sprite_exists, and if it doesn't it's an error.
"sprite_exists(ind) Returns whether a sprite with the given index exists."
So...now I'm thinking that applies to the room in question...

"When life gives you lemons, take them and run."
--me