Character save at save point
- supadupa64
- Posts: 200
- Joined: Sun Mar 06, 2016 9:40 pm
- Contact:
Re: Character save at save point
Hey so here's another thing. My load works every time except for the first time as usual. But here's another issue.
When I go through a trigger to do something it doesn't save . What would I add to the trigger to the game remembers when the sequence is? I have a sequence trigger on a trigger collider.
When I go through a trigger to do something it doesn't save . What would I add to the trigger to the game remembers when the sequence is? I have a sequence trigger on a trigger collider.
Game I'm working on:
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Re: Character save at save point
Hi,
I'll use a concrete example to explain the process. Let's say you have a sequence that drops a bunch of rocks from the ceiling when the player first enters a cave. You want your saved game to remember that the player has previously entered the cave so it doesn't incorrectly drop those rocks again.
Here are the steps:
1. Define a Lua variable named "EnteredCave". Set its Type to Boolean and its value to False. This variable will always be recorded in your saved games.
2. Set up a trigger collider GameObject in the mouth of the cave, and add a Sequence Trigger.
3. Open the Sequence Trigger's Condition section, and add this Lua condition:
This means the Sequence Trigger will only fire if EnteredCave hasn't been set true yet.
4. In the Sequence field, add your sequencer commands to make the rocks fall. Also add a SetVariable() sequencer command to set EnteredCave true. For example:
That should handle the sequence/saved game issue. But it still bugs me (and I'm sure you, too) that the game doesn't load properly the first time. If you ever want me to dig into this, please send me a reproduction project. I'll PM you access info for the FTP site, which can handle files up to 4 GB. If your project is bigger than that, you'll need to find another way to get it to me, such as Dropbox.
Use a Lua variable to remember it.supadupa64 wrote:Hey so here's another thing. My load works every time except for the first time as usual. But here's another issue.
When I go through a trigger to do something it doesn't save . What would I add to the trigger to the game remembers when the sequence is? I have a sequence trigger on a trigger collider.
I'll use a concrete example to explain the process. Let's say you have a sequence that drops a bunch of rocks from the ceiling when the player first enters a cave. You want your saved game to remember that the player has previously entered the cave so it doesn't incorrectly drop those rocks again.
Here are the steps:
1. Define a Lua variable named "EnteredCave". Set its Type to Boolean and its value to False. This variable will always be recorded in your saved games.
2. Set up a trigger collider GameObject in the mouth of the cave, and add a Sequence Trigger.
3. Open the Sequence Trigger's Condition section, and add this Lua condition:
Code: Select all
Variable["EnteredCave"] == false
4. In the Sequence field, add your sequencer commands to make the rocks fall. Also add a SetVariable() sequencer command to set EnteredCave true. For example:
Code: Select all
SetActive(Rocks);
Audio(Rumble);
SetVariable(EnteredCave, true)
- supadupa64
- Posts: 200
- Joined: Sun Mar 06, 2016 9:40 pm
- Contact:
Re: Character save at save point
Got it thanks!
Here's the thing. I have about 60 or so triggers in the game. A lot of them just enable or disable objects with SetActive(). Are you saying that if I want the game to save the SetActive() command I have to set up a variable for every sequence trigger?
Here's the thing. I have about 60 or so triggers in the game. A lot of them just enable or disable objects with SetActive(). Are you saying that if I want the game to save the SetActive() command I have to set up a variable for every sequence trigger?
Game I'm working on:
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
- supadupa64
- Posts: 200
- Joined: Sun Mar 06, 2016 9:40 pm
- Contact:
Re: Character save at save point
Let's say my player goes through a trigger collider and it enables lots of trees. If I go through that trigger, save the game, then load it, those lots of trees are not there because the trigger didn't save. Maybe you got that the first time though.
Game I'm working on:
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Re: Character save at save point
You don't really have to set up the variables ahead of time.supadupa64 wrote:Here's the thing. I have about 60 or so triggers in the game. A lot of them just enable or disable objects with SetActive(). Are you saying that if I want the game to save the SetActive() command I have to set up a variable for every sequence trigger?
If a variable isn't defined, it isn't true. [Corrected: It doesn't treat it as false, but as nil, which is not true.] So if "EnteredCave" isn't defined, the Condition 'Variable["EnteredCave"] ~= true' on the Sequence Trigger will still be true, so it will still run the sequence.
Likewise, if you put SetVariable(EnteredCave,true) in the sequence, it will automatically set up the variable for you if it's not already set up.
Use a Persistent Active Data component. For the tree example, let's say your Sequence Trigger looks like this:supadupa64 wrote:Let's say my player goes through a trigger collider and it enables lots of trees. If I go through that trigger, save the game, then load it, those lots of trees are not there because the trigger didn't save. Maybe you got that the first time though.
- Condition > Lua Condition: (not "==false")
Code: Select all
Variable["EnabledTrees"] ~= true
- Sequence:
Code: Select all
SetActive(TreesParent); SetVariable(EnabledTrees,true)
Add a Persistent Active Data component to any GameObject that starts active in the scene. Configure it like this:
- Target: TreesParent
- Condition > Lua Condition:
Code: Select all
Variable["EnabledTrees"] == true
- supadupa64
- Posts: 200
- Joined: Sun Mar 06, 2016 9:40 pm
- Contact:
Re: Character save at save point
Ok, so I add the Persistent Active Data component to any parent object that is activated through a trigger?
1) Trigger collider
sequence trigger - SetActive(tons of trees)
2) tons of trees (this is the name of the parentobject)
add Persistent Active Data component
yes?
1) Trigger collider
sequence trigger - SetActive(tons of trees)
2) tons of trees (this is the name of the parentobject)
add Persistent Active Data component
yes?
Game I'm working on:
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Re: Character save at save point
Close, but here are a few clarifications:
The Sequence Trigger needs to run SetActive(tons of trees) and SetVariable(ActivatedTrees), and it must have a Lua condition that Variable["ActivatedTrees"] isn't true (that is, it hasn't already activated the trees). [Corrected: This post previously said that the variable should be false. It should really be not-true.]
The Persistent Active Data component must be on a GameObject that starts active in the scene. So it can't be on tons of trees. You could create another GameObject, maybe called Persistent Active Components, and add all of your Persistent Active Data components to it.
The Sequence Trigger needs to run SetActive(tons of trees) and SetVariable(ActivatedTrees), and it must have a Lua condition that Variable["ActivatedTrees"] isn't true (that is, it hasn't already activated the trees). [Corrected: This post previously said that the variable should be false. It should really be not-true.]
The Persistent Active Data component must be on a GameObject that starts active in the scene. So it can't be on tons of trees. You could create another GameObject, maybe called Persistent Active Components, and add all of your Persistent Active Data components to it.
- supadupa64
- Posts: 200
- Joined: Sun Mar 06, 2016 9:40 pm
- Contact:
Re: Character save at save point
Ok, here's what I have so we can use this specific example below. It all works, I'm just trying to get it to save it's current state, active or inactive.
I would place the "persistent active data" component on the "empty gameobject" which I named "scrollstartmap?" I'm not sure if that's it because I tried that and it didn't work.
Here's what the empty game object looks like.
I would place the "persistent active data" component on the "empty gameobject" which I named "scrollstartmap?" I'm not sure if that's it because I tried that and it didn't work.
Here's what the empty game object looks like.
Game I'm working on:
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Re: Character save at save point
It's almost there! Persistent Active Data needs to be on a GameObject that's already active whenever the scene starts. Here's an example:
1. In your Sequence trigger, (1) set Condition to require that a variable ("MapTrigger" in this example) is NOT true using the "~= true" syntax [corrected from "==false"], and (2) in the Sequence, set the variable true:
2. On an active GameObject (not startscrollmap), add Persistent Active Data. Configure it to set startscrollmap active or inactive based on the value of the MapTrigger variable. In the screenshot below, I created a separate, active GameObject named "persistent active data":
I put it on a separate GameObject just to make the screenshot shorter. There's no reason why you couldn't put the Persistent Active Data component on the same GameObject as the Sequence Trigger (i.e., the maptrigger GameObject):
1. In your Sequence trigger, (1) set Condition to require that a variable ("MapTrigger" in this example) is NOT true using the "~= true" syntax [corrected from "==false"], and (2) in the Sequence, set the variable true:
2. On an active GameObject (not startscrollmap), add Persistent Active Data. Configure it to set startscrollmap active or inactive based on the value of the MapTrigger variable. In the screenshot below, I created a separate, active GameObject named "persistent active data":
I put it on a separate GameObject just to make the screenshot shorter. There's no reason why you couldn't put the Persistent Active Data component on the same GameObject as the Sequence Trigger (i.e., the maptrigger GameObject):
- supadupa64
- Posts: 200
- Joined: Sun Mar 06, 2016 9:40 pm
- Contact:
Re: Character save at save point
Do I need to reference a database?
Do I have to create a variable in the database or can I just type it into the lua without creating a variable in the database?
Do I have to create a variable in the database or can I just type it into the lua without creating a variable in the database?
Game I'm working on:
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/
Website: http://www.RuctionGames.com
Steam: http://store.steampowered.com/app/49682 ... en_Tablet/