Jump to content


Photo

Unknown Variable?


  • Please log in to reply
39 replies to this topic

#1 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 24 March 2011 - 04:33 PM

Hi, my variable (enemy_attack) is unknown. It's an error message I get. I have already set enemy_attack to 1 with the Create event, but when I go to play the game, it says its an unknown variable.
I don't see it anywhere in the forums, so can someone please help?
Thanks
  • 0

#2 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 24 March 2011 - 05:11 PM

So you set enemy_attack's value in the CREATE event of an object? And where are you trying to access it?

-IMP ;) :)
  • 0

#3 onyex

onyex

    GMC Member

  • New Member
  • 10 posts

Posted 24 March 2011 - 07:56 PM

Make sure you are creating the variable in the same object you are using the "enemy attack" variable in.

For example:
obj_enemy
-create
--variable (enemy_attack = 1)
-collision (enemy)
--create object (enemy attack; 0,0)

-NOT-

obj_enemy
-create
--variable (enemy_attack = 1)

obj_player
-collision (enemy)
--create object (enemy attack; 0,0)

In order to do the example above, a global variable must be created in order for different objects to see the variable.

I hope this helps!

-onyex
  • 0

#4 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 24 March 2011 - 07:58 PM

My friend from school helped me out, so it was solved. It was a Game Maker error, so I had to duplicate an obj_enemy, rename it to obj_tank, and set the enemy_attack to global. It works, so thanks for the help!
  • 0

#5 saim

saim

    GMC Member

  • GMC Member
  • 1086 posts

Posted 24 March 2011 - 08:26 PM

Just setting enemy_attack as a global variable would do. That's no game maker error.
  • 0

#6 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 25 March 2011 - 12:39 AM

There was an error, because setting another variable worked before. I mean, I have an odd version of the program, and this has happened before.
  • 0

#7 Canite

Canite

    Canigget

  • GMC Member
  • 1358 posts
  • Version:GM8

Posted 25 March 2011 - 12:42 AM

There was an error, because setting another variable worked before. I mean, I have an odd version of the program, and this has happened before.

Odd version? This not a bug with GM, it is either a mistake you made, or you're using some cracked version of GM.

edit: And if this cracked version can't even recognize declared variables, it's useless, and the free lite edition of GM would be better.

Edited by Canite, 25 March 2011 - 12:43 AM.

  • 0

#8 sabriath

sabriath

    12013

  • GMC Member
  • 3174 posts

Posted 25 March 2011 - 12:47 AM

That's hilarious...here is what I saw:


first post: I have a bucket that I put water into, it's red...but for some reason the blue one has nothing in it.
next post: I fixed it, I painted the red bucket green, and then poured the water all over the ground, now all the buckets have wet bottoms.

awesome!
  • 0

#9 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 25 March 2011 - 12:50 AM

sabriath... that was completely irrelevant... and no, it's not a crack, I didn't do anything wrong, it just didn't recognize variable attack for some reason, but recognized everything else.
  • 0

#10 sabriath

sabriath

    12013

  • GMC Member
  • 3174 posts

Posted 25 March 2011 - 12:58 AM

sabriath... that was completely irrelevant... and no, it's not a crack, I didn't do anything wrong, it just didn't recognize variable attack for some reason, but recognized everything else.

I'm 100% certain you don't know what you are doing. GM doesn't just randomly ignore commands given to it...it doesn't one day decide "I don't feel like working right now, your variables r belong to me now". It's not INTERCAL, and although bugs do creep in once in awhile where the compiler might skip a gmk block (which is very very very rare), a quick reload should fix the issue. You stated it isn't working at all, so that's not the problem.
  • 0

#11 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 25 March 2011 - 01:23 AM

Does the word NOVICE mean anything to you?
  • 0

#12 sabriath

sabriath

    12013

  • GMC Member
  • 3174 posts

Posted 25 March 2011 - 02:45 AM

Does the word NOVICE mean anything to you?

nope

there is do, and don't do....no try

A true novice would try to solve a root of a problem without blaming the tools they use. What you did was solve a surface problem (making the variable global doesn't change the fact that you are using it in the wrong place). A lot of the people here are willing to help you solve the root of your problems so that you don't come crawling back in here with the same type of question later. What you did was snubbed the tool because it couldn't possibly be your fault, and now we all know that you'll be coming back in a few weeks with another problem that would have and could have been solved right here right now.
  • 0

#13 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 25 March 2011 - 03:08 AM

Well you will get no where in life with THAT attitude :P
  • 0

#14 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 25 March 2011 - 04:59 AM

Even if you are a novice, deciding that if something doesn't work right it must be the IDE's fault is ridiculous. That's like saying "I never pressed the power button, but my TV's not turning on, so it must be broken; I can fix it by buying a new TV." Terrible logic to live by, and I'm using the word "logic" lightly.

In fact, though there are plenty of bugs in GM, 90% of the time something doesn't work in ANY language, it's the programmer's fault. Coming from experience, that is.

-IMP ;) :)
  • 0

#15 sabriath

sabriath

    12013

  • GMC Member
  • 3174 posts

Posted 25 March 2011 - 08:17 AM

By the way, my last post had a hidden message in it....if you haven't already seen it, try and find it.
  • 0

#16 MasterOfKings

MasterOfKings

    The True Master

  • GMC Member
  • 4888 posts
  • Version:GM8

Posted 25 March 2011 - 08:23 AM

A poor workman blames his tools... And computers never make mistakes, people cause them to make mistakes.

On that note, I'll leave you all to it.

-MoK
  • 0

#17 saim

saim

    GMC Member

  • GMC Member
  • 1086 posts

Posted 25 March 2011 - 12:13 PM

You problem was that you were adressing a variable from another object, so the object calling it couldn't recognize it.
When you declared it as a global variable, every object had access to it, includding the one you wanted.
Copying, renaming or anything else wasn't required.

That's true. Honest. No GM error.
While novice, we usually get a lot of bugs that we have a hard time figuring out what went wrong, but usually, that's our logic problems, not the GM's. Things that go wrong all the time are easy, just take the error report and try to figure out what may be causing it. Things that go wrong only now and then are the hard part, you keep thinking "if there is an error, why does it WORK most of the time?", but that's also our logic problem. There was this one time in... let me see... 2 years of game making, that the error was not my logic. I tried to run 2 games at once and my video card couldn't handle it, prompting a surface problem (both games made in lite version, meaning I didn't mess with surfaces). I got really curious, how could I have a surface problem without using surfaces? Again, no GM error, just a hardware limitation and the fact that the surfaces are used to draw everything in the game, even if we don't directly play with them.
I have seen many reports of bugged versions, but most of the time, it ended up being users mistakes. When there actually is a bugged copy, the normal error is that GM doesn't start or the games do not start.
  • 0

#18 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 25 March 2011 - 02:36 PM

Thank you saim. At least you didn't call me stupid. My friend looked at the version and it is in fact a bugged version. Yes, sabraith, I found your "hidden" message. If you're just going to call me stupid, don't respond to my post. My version is bugged because this is about the 10th time something like this has happened, that worked for my friend's version (3 years game maker experience). With that note said, you all (except saim and the others who helped me) are jerks who shouldn't be responding to my post only if you're going to insult me.
  • 0

#19 saim

saim

    GMC Member

  • GMC Member
  • 1086 posts

Posted 25 March 2011 - 05:12 PM

Don't feel bad about the things people said. Bugged versions are really rare and we all - includding me - got used to misbelieve reports of bugged versions, because it is really common to get those reports when the problem is actually in the human part. I mean, you're not the first one to say that your problems are caused by a GM error.
Besides, you DID fix it doing, amongst other things, change the variable to global, like we were implying that you should.

Being the 10th time something like that happens does not mean that your version is bugged. The same file that gave you the error work on other versions, probably does. But you still have to check if, for example, you're using a GM7 function in a GM8 copy and your friend has an older version, or vice-versa. Not likely, since it was a variable problem.
Basically, what everybody was saying (in less kind words) was "there is a logical problem there that you're the only who can't see. How can we open your eyes to that?".
  • 0

#20 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 25 March 2011 - 05:33 PM

Well, they could have been a bit nicer about it. The thing that confuses me is that if enemy_can_shoot works by setting it in code, why won't enemy_attack work the same way? Why do I have to change it to global?
  • 0

#21 Canite

Canite

    Canigget

  • GMC Member
  • 1358 posts
  • Version:GM8

Posted 25 March 2011 - 06:11 PM

The problem is in the way you use the variable. If you want to access the variable from a different object, you need to make it global. If only the same object is using that variable, it does not need to be global.
  • 0

#22 saim

saim

    GMC Member

  • GMC Member
  • 1086 posts

Posted 25 March 2011 - 06:30 PM

Canite posted the most usual cause. Right now, I'm feeling a little creative, so I thought of 3 other possible reasons:
- You DO declare enemy_attack in the right object, but not on the right event. In other words, you try to call it before you declare it.
- You declare enemy_can_shoot on a parent object and enemy_attack on a child object, but forgot about it and called enemy attack from an instance of the parent object.
- You declare both variables on the event that creates the instance (with(instance_create(x,y,enemy)), from another object) but only call enemy_can_shoot on the step event, while you do call enemy_attack on the create event of the same object. Wow, I confused myself, this time!

Check those out. If you can't find the reason, post the object and event that enemy_can_shoot is declared and the object and event it is used. The same for enemy_attack. Probably, you'll figure it out on your own before pressing the "add reply" button. But since making it global fixed the problem, I suppose Canite's explanation resumes it all.
  • 0

#23 FlamingShadow

FlamingShadow

    GMC Member

  • GMC Member
  • 21 posts

Posted 25 March 2011 - 07:02 PM

I think he means that enemy_attack and enemy_can_shoot are different variables
  • 0

#24 saim

saim

    GMC Member

  • GMC Member
  • 1086 posts

Posted 25 March 2011 - 07:21 PM

I think he means that enemy_attack and enemy_can_shoot are different variables

I understood that. Does my answer look like I understood differently?
  • 0

#25 sabriath

sabriath

    12013

  • GMC Member
  • 3174 posts

Posted 25 March 2011 - 10:00 PM

I say upload the broken file to a site and let us take a look. We can run around in circles all day long wondering "what went wrong" and "is this a legite GM bug", but it won't get us anywhere except for 2 factions of a feud:

first faction - those who believe you screwed up somewhere in defining the variable and using the variable in 2 different positions (whether it be in the same object, or you mistaked that both create events occur in a parent-child situation, which it doesn't).

second faction - willfully believes you in that you understand GM (or your friend does) enough to, without a doubt, know it's a GM bug.



Heck, this could all be just a glitch on your HDD that one of the GM blocks got distorted and ignored an entire code block until you altered it and resaved it...you have to give us something other than "it doesn't work....oh wait, i fixed it by doing something completely off-the-wall."
  • 0

#26 MasterOfKings

MasterOfKings

    The True Master

  • GMC Member
  • 4888 posts
  • Version:GM8

Posted 26 March 2011 - 09:22 AM

Although, I daren't start a flame war.. but exactly 'how' was this a GM error?

As in, what did GM do wrong?

What was the issue with that particular version of GM?

If the version is bugged, why does renaming one object and variable make it suddenly start working correctly?



Your appeal for being correct that it's GM's fault, isn't very well supported. It sounds more like you had some sort of resource name clash and GM didn't like it. So, you replaced the object, and the clash is gone.

-MoK

Edited by MasterOfKings, 26 March 2011 - 09:23 AM.

  • 0

#27 FlamingShadow

FlamingShadow

    GMC Member

  • GMC Member
  • 21 posts

Posted 27 March 2011 - 03:11 AM

It'd be much easier to just call you stupid, mr. greatvenom. Quit being a stubborn jerk and take these guys' advice. They know what they're doing.

Edited by FlamingShadow, 27 March 2011 - 03:54 AM.

  • 0

#28 saim

saim

    GMC Member

  • GMC Member
  • 1086 posts

Posted 28 March 2011 - 01:41 PM

It'd be much easier to just call you stupid, mr. greatvenom. Quit being a stubborn jerk and take these guys' advice. They know what they're doing.

Recently joined, knowing all about game maker and even about which members are experienced...
Sounds like a fake profile, to me. A fake profile of someone who, unlike some of us, WANTS to start a flame war.
  • 0

#29 FlamingShadow

FlamingShadow

    GMC Member

  • GMC Member
  • 21 posts

Posted 29 March 2011 - 02:07 AM

Hah, relax, I'm his brother.
  • 0

#30 greatvenom

greatvenom

    GMC Member

  • GMC Member
  • 43 posts

Posted 29 March 2011 - 02:13 AM

I haven't been able to figure out what's wrong, because the variables were used for different objects, and I set them before assigning them to objects. But let's not lose sleep over this, I'll admit I was wrong (though I don't know how) and we'll end it here. Setting it to global works. End of story. And yes, that was my brother being an idiot.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users