Page 1 of 1

a question about the forest world keys

PostPosted: 22 Feb 2018, 21:39
by sinisa3games
How do the forest world keys work? And is it possible to recreate it?

Re: a question about the forest world keys

PostPosted: 23 Feb 2018, 14:02
by mteufel
Using scripting. And yes.

Re: a question about the forest world keys

PostPosted: 23 Feb 2018, 15:10
by manuel
It's a bit more complicated than standard scripting in a level because you have to save information in the savefile, but you can do many things, that effect multiple levels with this mechanic.

Re: a question about the forest world keys

PostPosted: 24 Nov 2018, 20:12
by WeLuvGoatz
Can someone please explain, in detail, how? Or does someone have a link that leads to how I can recreate this?

Re: a question about the forest world keys

PostPosted: 25 Nov 2018, 14:24
by manuel
The levels probably have to be packed in the addon-format to test it, but I am not certain…
This is copied and shortend from the keys in the forest world.

So,
you need this file in the same folder where your levels are. You can name it whatever you like, but I recommend calling it "default.nut", as it will be imported automatically with this name.

{l Code}: {l Select All Code}
if(! ("your_name" in state))
  state.your_name <- {}
  foreach(name in ["name1","name2","name3"]){
    if(! (name in state.your_name))
      state.your_name[name] <- false;
}

function settotrue(name){
  state.your_name[name] <- true;
}

This will write something into your savefile. You can find it at "supertux2/profile1/your-levelset-id.stsg". (If you are using a different profile, open this profile instead.)
You can name "your_name" as whatever you want, as long as it contains only letters, numbers or _ or - . It must always have the same name where I use "your_name". For "name1", "name2" and so on (and for settotrue) it is the same. You can add more things between these brackets [ ] like this.
If you change something here after runnng it once, it will not correct the savefile, as it already finds something that is called "your_name". So you need to delete the section with "your_name" from the savefile again.
This should create something at the end of your savefile that looks like this:

{l Code}: {l Select All Code}
("your_name"
  (name1 #f)
  (name2 #f)
  (name3 #f)
)

You can now run settotrue("name1") in a script in your level. You can exchange "name1" with any value you want to set to true. You are then able to use:

{l Code}: {l Select All Code}
if(state.your_name.name1){
  Some scripting here…
}

or if you want to test whether it is not activated yet:
{l Code}: {l Select All Code}
if(state.your_name.name1 <- false){
  Some scripting here…
}