Tutorial: How to create locked gates easily


#1

Hi. Here I will post an easy tutorial about how you can add a “locked gate” event easily even without needing to study hard about scripting.

This is valid ONLY for gates. I will add soonly how to do it also for doors


Locked Gates

Simply follow those instructions:

  1. Use Editor and create a gate and set the param “is locked” to 1. Set the param “label” with an easy name (I suggest something like “gate_COLOUR” - example “gate_golden”)

  2. save the level and close frogatto

  3. open the level file (example “my_level.cfg”) with a text editor

  4. use the “search” function inside your text editor. You sould find your “character” tag (see the label parameter)

  5. you will see a list of params. After the parameter “label” (for example label=“gate_golden”) add the following lines. you will need some little changes. I will mark WHERE you need to change something

on_child_spawned="if(child.type in [[b]'lock_golden'[/b]],set(vars.locks, vars.spawned_locks + [child]))"

on_collide_object=“if(collide_with.type = ‘key_golden’, [fire_event(‘unlock’), fire_event(vars.locks[0],‘unlock’), set(collide_with.hitpoints, 0), set(level.player.vars.triggered_events, level.player.vars.triggered_events + [‘nobun01_gate_golden_unlocked’])])”

on_create=“if(‘nobun01_gate_golden_unlocked’ in level.player.vars.triggered_events,fire_event(‘unlock’), spawn(‘lock_golden’,midpoint_x-10,midpoint_y+31,1))”

A - here you will see spaces becouse every parameter will require a line only but the forum is unable to see the entire line. BUt, for better readability I suggest to don’t let those blank lines.

B - you must change ONLY the parameters I bolded. The other things not require any change.

C - ‘key_golden’ -> replace with your key (example ‘key_red’)

D - ‘nobun01_gate_golden_unlocked’ -> this is a var. It can be hard to explain what is it so I will leave a very-easy hint about how to rename it. I suggest to rename it as 'your_level_namegatecolour_unlocked’
where “your_level_name” is the filename of your level (must be unique and without spaces. Use _ instead)
and “colour” is the colour of the gate lock (for example ‘golden’, ‘red’ or ‘green’, …)

E - ‘lock_golden’ -> replace “golden” with the colour of the lock (for example if you must create a “red” lock use ‘lock_red’)

  1. Save the .cfg file with your editor

#2

Brief, but clear. :slight_smile: Thanks, Nobun.


#3

It’s important to know: this is for permanently unlocking a gate, like the one in crevice-village’s cave.

Everything on a level is deleted after you leave the level (it’s all reset to normal), so if we want something to stay changed (like having a gate stay unlocked), we have to record it somewhere. This is what that variable is for:
“nobun01_gate_golden_unlocked”

That gets added to our list of “things that have happened”; when the level gets started up, it checks if that’s happened, and if so, the lock in question doesn’t reappear.


#4

Thank for the explaination, Jetrel. As I said I have not studied the script system. I watched something in the wiki but the main structure of the code is not totally clear for me so It was easier to me to use an already coded script to obtain the effect I wanted to add (yeah, exactly the crevice village one :D) and see how to change it (I used my own logic :P)