ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 29, 2015 21:15:42 GMT
Make a subclass of "WorldVariableListener" and hook it up to your Experience Points world variable (drag it to Listener field). Inside the UpdateValue method of the Listener, you can add code to increase the Level (World Variable) when certain Experience Points are passed (100, 300, etc). This will require a little bit of code. Ok ty will try it.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 29, 2015 22:26:14 GMT
Can you do a tutorial on some of this things please, it will really help i think. Thanks again
|
|
|
Post by DarkTonic Dev on Mar 30, 2015 0:05:12 GMT
Sorry, but we have other more important videos (more commonly used features) ahead of that to do, already on the roadmap. Maybe in a few months I might have some time to get to others.
However, there are 2 examples of Listeners in the Youtube videos. I suggest you watch them all, they're pretty short and informative.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 30, 2015 19:51:26 GMT
However, there are 2 examples of Listeners in the Youtube videos. I suggest you watch them all, they're pretty short and informative. I don't see the two for listeners, the videos are mostly spawner,trigger, master audio then Killables & World Variables which i have watched too. Sorry about this just trying to understand it and couldn't get it to work mostly the subclass for the WorldVariableListener. Something like this ? using UnityEngine;
using System.Collections;
public class XPSystem : WorldVariableListener {
void Update(){
UpdateValue ();
}
public void UpdateValue() {
var variable = WorldVariableTracker.GetWorldVariable("Experience");
if(variable.CurrentIntValue >= 200){
var Levelvariable = WorldVariableTracker.GetWorldVariable("PlayerLevel");
Levelvariable.CurrentIntValue += 1; variable.CurrentIntValue = 0; //To set the CurrentIntValue to 0
}
}
}
This is works, made the max value for the Experience 200 but the problem now is how do i make the max experience needed keep doubling when its reached and the player gains a level, and and when i reset the CurrentIntValue to 0 they can start again to gain the next experience e.g 400 ?
|
|
|
Post by DarkTonic Dev on Mar 30, 2015 23:43:32 GMT
Yeah something like that. I wouldn't even give the Experience a max value. Just reset it to zero and increase the level. Really the code would probably be like:
// pseudo-code 1) If Level = 1 and XP >= 200, increase level to 2 and reset XP to 0 2) If Level = 2 and XP >= 400, increase level to 3 and reset XP to 0, 3) Etc.
The video showing a World Variable isn't a whole video, it's just a small piece of the video. It's probably in the World Variable video. It doesn't show any code, just hooking up a quick listener. Nothing special.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 31, 2015 9:19:27 GMT
Cool, thank you for all your help  .
|
|
|
Post by DarkTonic Dev on Mar 31, 2015 15:16:15 GMT
No problem.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 31, 2015 18:50:27 GMT
Hi, is there any way you can tell me how i can save the WorldVariables Names and Values maybe with playerpref i really need this ?
I have an inventory system vendor and i was able to get the vendor use/check Gold in the WorldVariables which works but gold in the WorldVariables is not updating.
Was thinking of something like
PlayerPrefs.SetString ("VARIABLENAME", variableName);
PlayerPrefs.SetString ("VARIABLEVALUE", _variableValue); in the WorldVariableListener but not sure is right were best to put to save up all the different Names and Values in the WorldVariables that way it will be easy for me call and set them in any script.
|
|
|
Post by DarkTonic Dev on Mar 31, 2015 19:56:37 GMT
You can save them into PlayerPrefs if you like, but I wouldn't do that "every time a variable is updated" as that will be terrible for performance. We use "cached player prefs" instead of the Unity PlayerPrefs because it's about 100x leaner and faster.
You know the 2 lines of code to read or set a WorldVariable, so it's only a matter of picking a "save point" where you will save or load them, and then reading or saving.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 31, 2015 21:04:50 GMT
K, I will just see how i can use easy save 2 to save since i have it and if it does work then i will end up not using Core GameKit or maybe just leave out WorldVariables.
|
|
|
Post by DarkTonic Dev on Mar 31, 2015 23:46:47 GMT
I'm sure you can use Easy Save to save and load World Variables. But you'd need to ask the author of that plugin how to customize it. But it would probably be just as easy to write a class to load and save a bunch of World Variables.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Apr 1, 2015 0:17:55 GMT
Got the saving done like this in the WorldVariableListener.cs, which worked the problem now is am getting error when am trying to retrieve the value for Gold for example. I have emailed the author just waiting for replay.
public virtual void UpdateValue(int newValue) {
_variableValue = newValue;
var valFormatted = string.Format("{0}{1}",
displayVariableName ? variableName + ": " : "",
_variableValue.ToString("N0"));
if (!useCommaFormatting) {
valFormatted = valFormatted.Replace(",", "");
}
if (_text == null || !SpawnUtility.IsActive(_text.gameObject)) {
return;
}
_text.text = valFormatted;
using(ES2Writer writer = ES2Writer.Create("WVL_Int_File.text")){
// Write our data to the file.
writer.Write(this.variableName, variableName+"NameTag");
writer.Write(this._variableValue, variableName+"ValueTag");
// Remember to save when we're done.
writer.Save();
}
}
|
|
|
Post by DarkTonic Dev on Apr 1, 2015 4:56:04 GMT
It uses text files, interesting. So does the Cached Player Prefs we're using.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Apr 1, 2015 21:03:44 GMT
ah, the saving works it it save up all the World Variable the values and i know how to get the value but am just trying to figure out how i can load them all to the right place when the scene starts again
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Apr 1, 2015 21:09:24 GMT
The author of the inventory am using helped me connect the gold WorldVariable i made with his inventory vendor 
|
|