playMaker

Author Topic: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE  (Read 6240 times)

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« on: February 26, 2014, 09:43:29 AM »
How do i handle a global game object variable from changing between scene's

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #1 on: February 26, 2014, 09:49:50 AM »
Can you give an example?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #2 on: February 26, 2014, 11:09:43 AM »
YES, i have a ten G.O.(dogs) that can be selected, when one is selected it set's the global G.O. variable " dog a chosen" to (dog 1) (if dog 1 was the one selected)
then when i go to another scene, the G.O. variable has been cleared, the dog i selected isnt set in the G.O. variable "dog a chosen" anymore,

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #3 on: February 26, 2014, 11:24:20 AM »
When you switch scenes it doesn't carry any information over from the old scene.

Use DontDestroyOnLoad if you want to retain objects between scenes.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #4 on: February 26, 2014, 12:03:08 PM »
THANK YOU LANE, that worked, but now when i leave scene one and go to scene 2 then back to scene one, there are two of them! what am i missing? what do i do? thanks again.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #5 on: February 26, 2014, 12:24:28 PM »
Depends on how you're creating the dogs, I guess. If level 1 creates a dog that will not be destroyed on load then it will be in the next level, whatever that may be. So if you spawn another one it would keep creating them as you switch levels.

Maybe do a check to see if the global dog variable is null and skip creation if it isnt it?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #6 on: February 26, 2014, 01:11:00 PM »
The dogs are in scene one to begin with, they are in a kennel, then when selected it will run a itween path to a car and become a child of the car, then i drive the car to a spot on the terrain and when i get out of the car it sends me to another scene 2. then when i am done in that scene i click on the car and it will send me back to scene 1 where i drive home. and it is all working except when i go from scene 2 back to scene 1 there are 2 players, 2 cars, 2 dogs all the same.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #7 on: February 26, 2014, 01:27:36 PM »
If you have the dogs in scene 1 already, then when you load it again it will have two dogs because the one from the previous scene will still be retained.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #8 on: February 26, 2014, 01:35:03 PM »
yes, that is what is going on, (sorry sometimes i dont type what i think, lol) so any suggestions on how to stop it from loading it twice?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #9 on: February 26, 2014, 01:49:00 PM »
You can destory the dog on level 2 right before you switch to level 1 or create the dogs at runtime in level one, but first check if the global is null, to see if a dog is coming from level 2.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #10 on: February 26, 2014, 03:24:29 PM »
I just cant figure out how to destroy an object that came from a previous scene. i am trying to use destroy object , but cant set it up in the scene if the object isnt there yet.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #11 on: February 26, 2014, 03:27:44 PM »
Destroy it before leaving the scene.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #12 on: February 26, 2014, 03:32:12 PM »
yes but how? i can't set a 'destroy G.O.' action because the G.O. isnt in the scene yet. i must be missing something.
« Last Edit: February 26, 2014, 03:35:29 PM by wallaceb68 »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #13 on: February 26, 2014, 03:48:33 PM »
Destroy the one that is persisting through the scenes before you switch levels, or spawn the dogs at runtime in each level and test to see if they already exist. If they do, then you can skip creating them.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #14 on: February 26, 2014, 11:38:26 PM »
OK, IM STILL NOT GETTING THIS, how do you set-up something in a scene to be destroyed, that isnt in the scene yet? or how do you check the count of a specific G.O. in a scene and if it is more than one i can us destroy self! i have tried setting a global G.O. variable and the the G.O. to the car but when i switch scene's it lose's the preset. i thought global's where to keep there value globally!
« Last Edit: February 26, 2014, 11:45:26 PM by wallaceb68 »