Jump to content


Photo

Loading variables


  • Please log in to reply
14 replies to this topic

#1 Gug1st

Gug1st

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 03 June 2012 - 07:02 PM

I'm trying to load variables from one object in a room to another object in another room. Any ideas?
  • 0

#2 Debels

Debels

    GMC Member

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

Posted 03 June 2012 - 07:06 PM

I'm trying to load variables from one object in a room to another object in another room. Any ideas?


Well you can make the object persistent so it will be on the other room with the same variables
  • 0

#3 Gug1st

Gug1st

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 03 June 2012 - 07:15 PM

The problem is that the first object isn't meant to be on the next room.

Example: I click on a button to change a sprite in the next room, but it doesn't change it. This is somewhat my problem
  • 0

#4 Debels

Debels

    GMC Member

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

Posted 03 June 2012 - 07:33 PM

The problem is that the first object isn't meant to be on the next room.

Example: I click on a button to change a sprite in the next room, but it doesn't change it. This is somewhat my problem


Oh, then use Global Variables, example:

global.sprite=spr_this;

  • 0

#5 Gug1st

Gug1st

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 03 June 2012 - 07:46 PM

Still, there's a problem. I first used a script to define a global variable.

This is what I got:

globalvar char;

Then I set the button to:

char = 14;

In the object I want after for the next room, I still dunno how to do with global variables. Just seems too weird :S
  • 0

#6 Debels

Debels

    GMC Member

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

Posted 03 June 2012 - 07:50 PM

Still, there's a problem. I first used a script to define a global variable.

This is what I got:

globalvar char;

Then I set the button to:

char = 14;

In the object I want after for the next room, I still dunno how to do with global variables. Just seems too weird :S


I think "globalvar" makes the variable temporary for that room only i think, use global.char = 14;

Edited by Debels, 03 June 2012 - 07:51 PM.

  • 0

#7 Gug1st

Gug1st

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 03 June 2012 - 07:55 PM

I tried defining the global.char, but when I try adding it on the object, it still says that it's not defined
  • 0

#8 NukeTheCat

NukeTheCat

    GMC Member

  • GMC Member
  • 460 posts
  • Version:GM8.1

Posted 03 June 2012 - 08:08 PM

Define it in the Create Event.
Unlike globalvar or var, 'global.' can't be defined anywhere else.
Once you defined it there you can use it anywhere else.

Edited by Jlm07, 03 June 2012 - 08:09 PM.

  • 0

#9 cantavanda

cantavanda

    GMC Member

  • Banned Users
  • 980 posts
  • Version:GM:Studio

Posted 03 June 2012 - 08:13 PM

Use a global variable.
global.anything = 1


#10 Debels

Debels

    GMC Member

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

Posted 03 June 2012 - 08:26 PM

Use a global variable.

global.anything = 1


Thats what we said.........
  • 0

#11 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2057 posts
  • Version:Mac

Posted 03 June 2012 - 08:47 PM

Define it in the Create Event.
Unlike globalvar or var, 'global.' can't be defined anywhere else.
Once you defined it there you can use it anywhere else.

Actually, global variables can be defined anywhere (except maybe not in scripts... not sure) as long as they are defined before being used. It's best to just define them in the create event though, since it's more organized.
  • 0

#12 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 03 June 2012 - 08:49 PM

I think "globalvar" makes the variable temporary for that room only i think, use global.char = 14;


Nope, it doesn't. It just means you don't have to write 'global.' everytime you are in your code.
  • 0

#13 Debels

Debels

    GMC Member

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

Posted 03 June 2012 - 08:54 PM


I think "globalvar" makes the variable temporary for that room only i think, use global.char = 14;


Nope, it doesn't. It just means you don't have to write 'global.' everytime you are in your code.


Oh, Thanks for removing that doubt of my head :)
  • 0

#14 NukeTheCat

NukeTheCat

    GMC Member

  • GMC Member
  • 460 posts
  • Version:GM8.1

Posted 04 June 2012 - 12:01 PM

Maybe the variable gets destroyed when the object itself gets destroyed.

Try creating a sprite-less object, set the global variable, and then making it persistent.
  • 0

#15 Katuko

Katuko

    GMC Member

  • GMC Member
  • 4881 posts

Posted 04 June 2012 - 01:25 PM

Global variables do not belong to any particular instance and will not go away until the game ends. They can be declared anywhere, at any time. As with any variable, you will only get an error if you try using it for functions or calculations before it has been set to a value.

Show us the code/object information, please.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users