Text-only post today, sorry ’bout it!
I promised a follow-up post on Switches in Vidar. First, I talked about how the key to Switches is that one event can toggle another’s self-switches. Then I talked about how I use a modified Event Spawn script to dynamically place all of the puzzle parts at the start of a new game, and told you that I do the same for Switches.
Here’s the dilemma; placing things like barrels and wolves is easy, they always do the exact same thing. That means that all of the logic is self-contained in the event, and Event Spawn just copy/pastes it accordingly. Switches are not only puzzle-dependent, they’re option-dependent. One option in a specific puzzle slot might use a Switch to open a door, while another rotates an arrow. So I had to make a system where the logic inside a Switch is always the same, and it knows exactly which function to call.
An event knows its own Event ID. And an event can always get the current Map ID through the command editor. And an Event ID is unique per map, which means that every single event in the game has a unique combination of Map ID and Event ID. And now, we’re in business.
So when I spawn a Switch, I take a few extra steps. I have a hash called $chosenSwitches which maps [mapid, event id] to a Switch object. Once I’ve spawned the switch, I know all of that information:
new_event = EventSpawn.spawn_event_map(34, switch.map, switch.graphic, x, y, true, 0) switch.id = new_event.id $game_self_switches[[puzzle.map, switch.id, "B"]] = true if switch.dark == true $chosenSwitches.merge!([switch.map, switch.id] => switch)
The first line creates the Switch event, and a reference to it. The second line takes that event’s id and stores it in the Switch object. The third is unique to the Dark Cave biome – if the Switch is supposed to be “dark” (that is, invisible unless a light is on nearby), then turn self-switch “B” on for that event. The last adds our mapping to the $chosenSwitches hash.
Practically speaking, our event is now mapped to an object, which opens up a world of possibilities. Each Switch can have a function .call, which is unique to that Switch. When building the option, I can set each function by hand, but the logic inside each switch is the same:
mapid = $game_variables eventid = @event_id switch = $chosenSwitches[mapid, eventid] switch.call
This is the general gist of things – there’s a little bit more (that has to do with saving $chosenSwitches, and why it’s impossible with this set up) – but I’ll save that for another time!