Jump to content


Photo

Error


  • Please log in to reply
8 replies to this topic

#1 MasterMay

MasterMay

    GMC Member

  • New Member
  • 22 posts
  • Version:GM8

Posted 24 April 2012 - 03:18 PM

Can any one help me out?

I keep getting this message:

of Create Event
for object global.kid2:

Error in code at line 1:
x = global.kid2;
^
at position 12: Unknown variable kid2
  • 0

#2 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 24 April 2012 - 03:22 PM

This resource name is invalid. It uses the dot, which has special meanings in GML for referencing variables within an object instance. You should rename your object obj_kid2 or oKid2 depending on your preferences.

GameGeisha
  • 0

#3 MasterMay

MasterMay

    GMC Member

  • New Member
  • 22 posts
  • Version:GM8

Posted 24 April 2012 - 03:28 PM

Thanks for your help But it works on one part of the code but not on the other for example:
x = global.kid2;
y = global.kid2;

x = global.kid2;

This will work but

y = global.kid2;

will not and i dont no why.
  • 0

#4 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 24 April 2012 - 03:35 PM

Did you make an object called global.kid2?
Don't do this.
Call it something like obj_kid2.

Now try explaining a bit better what you are actually trying to achieve here because it looks like you're on completely the wrong track...
  • 0

#5 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 24 April 2012 - 03:40 PM

Thanks for your help But it works on one part of the code but not on the other for example:
x = global.kid2;
y = global.kid2;

x = global.kid2;

This will work but

y = global.kid2;

will not and i dont no why.

This is exactly what I mean by "invalid resource name". Your resource name is confusing the GM runner because it contains characters that have special meanings in GML. As a result, you can get unexpected behaviours like this that make no sense.

I will say this one more time: change the object name to something valid, like obj_kid2 or oKid2. Also, you will need to specify exactly which variable from your object you're retrieving. Assuming that you have already changed the resource name:
x = obj_kid2.x;
y = obj_kid2.y;

GameGeisha

Edited by GameGeisha, 24 April 2012 - 03:41 PM.

  • 0

#6 MasterMay

MasterMay

    GMC Member

  • New Member
  • 22 posts
  • Version:GM8

Posted 24 April 2012 - 03:49 PM

Ok guys this is the overall problem i have.

I am trying to make a battle system like pokemon but i am stuck on the transition part.

I have my obj_battle and i have made it so if it collides with obj_char saves the game and then enter battle room.
Once your in the battle room i have a run button so that when enter has been pressed load saved game which takes me back to the previous room and my obj_char is in the same position.

BUT!!! that's the problem in order to go back to the previous room and keep my obj_char in the same position before i left i have to save and load the game which then means everything i have done in the battle for example use a potion has been discarded because the game saved before the battle.

So i not only need a way to go back the the last room i was in without saving and loading the game but i also need my char to be in the same spot i left him in when i get there.

And someone told me to do this:

// Enter a battle
global.playerX = x;
global.playerY = y;

// Enter the world after the battle
x = global.playerX;
y = global.playerY;

Is this correct???
  • 0

#7 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 25 April 2012 - 02:21 AM

Ok guys this is the overall problem i have.

I am trying to make a battle system like pokemon but i am stuck on the transition part.

I have my obj_battle and i have made it so if it collides with obj_char saves the game and then enter battle room.
Once your in the battle room i have a run button so that when enter has been pressed load saved game which takes me back to the previous room and my obj_char is in the same position.

BUT!!! that's the problem in order to go back to the previous room and keep my obj_char in the same position before i left i have to save and load the game which then means everything i have done in the battle for example use a potion has been discarded because the game saved before the battle.

So i not only need a way to go back the the last room i was in without saving and loading the game but i also need my char to be in the same spot i left him in when i get there.

And someone told me to do this:

// Enter a battle
global.playerX = x;
global.playerY = y;

// Enter the world after the battle
x = global.playerX;
y = global.playerY;

Is this correct???

Wait...why do you load a saved game just to leave the battle room?
Just change rooms back to the world room.
Then the code above will work assuming you hero is persistent (checkbox in object properties), and the game will still know that you consumed a potion before you fled, how much hp you have etc.


Extra notes:
If you're going to use persistent hero though, you will need to manually deactivate him for any rooms you don't want him to appear in such as map or shop.
The other way to do it that I know of (interested in better suggestions!) is to just store all the progress information (stats, inventory etc) in somewhere else like global, so that you can create and destroy the hero object without losing any information.
That is IMO a better way to do it especially if you plan to grow your game.

Edited by decroded, 25 April 2012 - 02:22 AM.

  • 0

#8 darkclower

darkclower

    GMC Member

  • New Member
  • 80 posts
  • Version:GM8

Posted 25 April 2012 - 07:22 AM

Hello again.
Btw, I'm the one who told him to use global variables.

But I forgot to tell you that you need to create the variables when you load or create a new save.

I also need to tell you this before you go on.
An instance can load and set other instance's variables.
And this is similar to the way an instance loads and sets global variables.
As you know, global variables have global. before them.
So an instance's variable has either "(id)." (Replace id with the instance's id and remove the ") or "object_index." (Replace object_index with the instances object index, and remove the " once again).
So when you load and set a global variable, you can pretend it's an persistent object that can't execute code.
To learn more about variables, read about it in the Game Maker Manual (Press F1 in Game Maker to open it).

So when you create a new game, it should look something like this (This is in the room before, like the main menu).
// Variables. You may add any variables you need, like HP or items.
global.playerX = 0; // The start X for the player (replace 0 with where the player will spawn)
global.playerY = 0; // The start Y for the player (replace 0 with where the player will spawn)
global.playerMaxHp = 100; // The players max hp
global.playerHp = global.playerMaxHp; // Sets the players hp to the max hp

I hope this works.

Edited by darkclower, 25 April 2012 - 07:22 AM.

  • 1

#9 MasterMay

MasterMay

    GMC Member

  • New Member
  • 22 posts
  • Version:GM8

Posted 25 April 2012 - 11:02 PM

Thank you all it WORKED!!! :D
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users