How do I save a random variable

Get help using Construct 2

Post » Wed Sep 20, 2017 11:03 pm

Ok, so I am creating a random character creation sheet which looks at a global variable such as var_Name and sets ones of the variable text to the text file I have on the layout using this

Code: Select all
tokenat(var_Name,floor(random(tokencount(var_Name,";"))),";")


Now I have everything working so far but I need to find a way to save the randomly chosen information either locally or online or even both, so that I can allow the player to reload this data and be able to call it up & reference it in game, so my overall question, is there any way I can save a randomly chosen piece of text from a global variable into a savefile.
B
93
S
45
G
33
Posts: 93
Reputation: 23,483

Post » Wed Sep 20, 2017 11:19 pm

Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
127
Posts: 1,762
Reputation: 67,845

Post » Thu Sep 21, 2017 12:19 am

@dop2000

Thanks! Those are some good resources, but I am still a bit lost on

Say I.E I have a global variable var_Name = "John; Sally; Joe"
Now say the text choose Sally randomly out of that, how would I save that specific information is what I need to know, I went threw most of that information you gave and I can't seem to figure that part out :#
B
93
S
45
G
33
Posts: 93
Reputation: 23,483

Post » Thu Sep 21, 2017 6:51 am

When you select your random name "Sally", put it into some other variable, say PlayerName . Then write this variable to the Local Storage.

Code: Select all
When player starts a new game do this:
PlayerName=tokenat(var_Name,floor(random(tokencount(var_Name,";"))),";")  // select random name from the list
playerNameText Set Text to PlayerName  // update text on the layout
LocalStorage set "PlayerNameKey" to PlayerName  // save name to local storage

When player loads saved game:
retrieve "PlayerNameKey" from Local Storage into the variable PlayerName (see tutorials on how to do it properly)
playerNameText Set Text to PlayerName  // update text on the layout
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
127
Posts: 1,762
Reputation: 67,845


Return to How do I....?

Who is online

Users browsing this forum: nicolalucky, nvdd and 24 guests