playMaker

Author Topic: PlayerPrefs and Events between [SOLVED]  (Read 4943 times)

Mayhem

  • Full Member
  • ***
  • Posts: 171
PlayerPrefs and Events between [SOLVED]
« on: April 14, 2013, 07:27:09 AM »
Hey there.

So I have a "little" problem, which i would like to solve with PlayMaker.
This is the thing:

The Game has its levels which are all single scenes. The levels/scenes can be entered on a worldmap, which is another scene.
There are also quests within the levels/scenes.

For Example:

The Player beats Level 5 and in Level 7 he meets a Character who has got a Quest for him, forcing the Player moving back to Level 5 and get the Item or Whatnot, and that certain Item only shows up in Level 5 when the Quest is accepted.

Within a Scene this would be a really simple task, but how should i handle something like this with more scenes. Could be PlayerPrefs the solution? If so, how could i do that with PlayMaker?

Another thing would be the Saveprogress at all. The Game will have only AutoSave-Features. Like, when one Level is finished, it saves the game (with all its Status, like the accepted Quests etc.).
How could i accomplish that with PlayMaker?
« Last Edit: April 18, 2013, 01:53:49 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlayerPrefs and Events between Scenes?
« Reply #1 on: April 15, 2013, 02:06:55 AM »
Hi,

 Get ArrayMaker, there is a an example doing just that, it doesn't load new scenes, but bascially it is the same principle and all based on player prefs.

look at the CheckPoints scene.

https://hutonggames.fogbugz.com/default.asp?W715

bye,

 Jean

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: PlayerPrefs and Events between Scenes?
« Reply #2 on: April 15, 2013, 08:07:13 AM »
Hey jean! Thanks for the reply.

Saving and Loading shouldn't be a big problem, i think i could handle that with ArrayMaker but for now i don't know how exactly i could achieve the Scene-To-Scene-QuestSystem as it doesn't take place in the same scene. The idea was:

1. In Level 5/Scene 5 there is an Item, which is deactivated. Another empty GameObject has a FSM with a Global-Transition, waiting to be triggered.
2. In Level 7/Scene 7 the Player gets the Quest to search for that Item.
3. Now the Player has the Quest in his Questbook
-> as soon the Player enters Level 5 the Quest-Entry will send the Trigger-Event to the FSM of the Empty Gameobject in this Level which will cause the Item to appear in this level.

How shall i tackle this with ArrayMaker? I have no idea right now :/

MurDocINC

  • Playmaker Newbie
  • *
  • Posts: 8
Re: PlayerPrefs and Events between Scenes?
« Reply #3 on: April 15, 2013, 05:37:40 PM »
Hey, I did a quick search and found http://whydoidoit.com/unityserializer/
Save/Load system for Unity, it has Playmaker actions. Give it a try and tell me how it goes. I wanna do the same in the future.

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: PlayerPrefs and Events between Scenes?
« Reply #4 on: April 15, 2013, 06:01:18 PM »
Thanks for the reply, but i am already using that Serializer ;)
The Game-Saving/Loading won't be that difficult, it's the Event-Quest-System which is bothering me...

MurDocINC

  • Playmaker Newbie
  • *
  • Posts: 8
Re: PlayerPrefs and Events between Scenes?
« Reply #5 on: April 15, 2013, 08:40:24 PM »
Ok, I found something.
Make a script with this:http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
Attach it to your "quest manager" object and any other object you need. Hopefully it will keep it as is. Dunno, give it a try and let me know.
Opps, there's also "Don't Destory On Load" action in playmaker that does the same.
« Last Edit: April 15, 2013, 10:14:08 PM by MurDocINC »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlayerPrefs and Events between Scenes?
« Reply #6 on: April 16, 2013, 12:32:20 AM »
Hi Mayhem,

 in level 5, you also need to do a full check on the quest and insert "if" statements so that indeed you trigger events when it's necessary, that's the best advice I can give given what you are describing, I do that all the time. You start with a very straight forward "reaction", and then you insert states in between the flow to take more decision and build a fsm that starts taking in account more and more properties of your game.

The player prefs are good for simply data, I would not recommand you use that to host all your quests, and I have ticked a new task for arrayMaker next update to allow for serializing array content which will make things easier. Also the dontdestroy feature if mandatory here, have a gameObject hosting the arrays and hash hosting your quests and questbook set to survive loading, and each level can then query that gameObject to know exactly the state of the game and react properly and differently.

 Bye,

 Jean

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: PlayerPrefs and Events between Scenes?
« Reply #7 on: April 16, 2013, 07:14:01 AM »
You suggest:

- i have a certain GameObject, let's call it "QuestManager"
-> this QuestManager is present in every single scene of the game and i ensure this by using the Don'tDestroyOnLoad-Method/Action
- this QuestManager is handling the Quest via an Array (with the ArrayMaker) and can, thanks to not be destroyed after loading, sending events to gameobjects of other Scenes.

So, do i get this right? If so I could tackle it this way, couldn't I:

- getting the Quest from Level 7, the Quest will be an entry in the Array/Hashtable
- beeing an Array or Hashtable (the QuestManager) i could check then, once the Player is in Level 5 again if the certain Questentry has a certain Key (for example a String which i defined), if so i could send events.

Would this be a possible solution? I'm just brainstorming here :D

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: PlayerPrefs and Events between Scenes?
« Reply #8 on: April 17, 2013, 06:57:07 PM »
Well well, i tried that and it is working!
- The MasterQuestManager is a Hashtable, where i check the Keys and Values.
-> That GameObject is present in every scene (DontDestroyOnLoad).
- every scene has its own LevelQuestManager, where the FSM of these Managers find first the MasterQuestManager (Find Object by Tag) and check the Keys and Values and send some certain Events on success/failure.

If there are any further suggestion, i'll be glad to hear them, but for now it works really fine.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlayerPrefs and Events between Scenes?
« Reply #9 on: April 18, 2013, 01:53:30 AM »
perfect I'd say!

 bye,

 Jean