fungus

Open full view…

Any advice (for a newbie) on flow for Fungus/C# game?

ehance
Sat, 25 Mar 2017 07:54:29 GMT

Hi all, I've enjoyed reading this forum for several months, worked through the Udemy course and have created a few small games using Fungus (has me excited)! Next I was planning to try something a bit bigger... I was hoping to create a Fungus story where I'm calling a C# game asset for some platforming here and there. After doing some reading I'm assuming I would use PlayerPrefs.Set/Get to store variables between Fungus and C# (or am I overthinking this)? This is my roughly assumed flow: -Launch game using Fungus (Start Block) -In Flowchart or Start Block create public variable for Dignity Points {PlayerPrefs.SetInt("Player Score", 0);} -During Fungus blocks add player score to --- {PlayerPrefs.SetInt("Player Score", 5);} -In Fungus Block call C# script (to launch other game asset)  -display score during C# asset runtime --- {print(PlayerPrefs.GetInt("Player Score"));} -add to it while C# script is running --- {PlayerPrefs.SetInt("Player Score", 10);} -C# script updates score to --- {PlayerPrefs.SetInt("Player Score", 15);} -C# script launch new flowchart or next bloc k...  --- flowchart.ExecuteBlock (“blocktoExecute”); -and continue this pattern... Until now I've stayed in the Fungus flowchart UI and haven't written any code, so I wanted to find gaping holes in my plan before starting... any thoughts or caveats? Any advice on best practices for this sort of scenario? (Or even any links you think me help me see the bigger picture). I enjoy the positive, helpful tone of this forum. :) Thanks in advance! -Eric

wolfrug
Sat, 25 Mar 2017 09:32:52 GMT

Oh wow, I never even thought of using PlayerPrefs to move variables from Fungus to C#! That's certainly one way of doing it - especially if we're only talking a small handful of variables. Clever! I don't know how much processing power constantly referencing playerprefs takes though - if that's the kind of thing you want to do several times a frame - but I suppose that as long as we're talking just one or two variables, it should be just fine? :D The other, much easier, way of moving vars between Fungus and a script is to use Invoke Method or Invoke Event (under Scripting). Just add a function to your C# script that allows to set the necessary variables (i.e. public void SetScore(int score) {PlayerScore = score;}, and the same for GetScore but as a public int with a return var, can be picked up by Invoke Method). In fact I think with Invoke Event, as long as you set it to i.e. "Dynamic Integer" instead of "Static", you can just set a public integer variable directly on a script from a Fungus var. But PlayerPrefs totally works too ;)

ehance
Sat, 25 Mar 2017 18:23:25 GMT

Thanks for the feedback Wolfrug! As you say its only a couple of vars, but I'm always glad to hear other good options. I'll give invoke a shot first, one planned follow-up question I had involved asking if I could just use a Public var to share a value between my Fungus Flowchart and a C# script (I'm new to Unity and wasn't sure how much can be shared between Lua and C#, sounds like it can that just fine). I've done some scripting in 3dsMax and am still learning how Unity stores things. :) -Eric