Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Variable problem

So here's the deal. I just started this the other day and decided to make a basic 5 min 2 map game just to test the basics and get used to some of this stuff. Everything works fine except for the variable. I have a common event on the first map that sets the variable to 10 (this is the players reputation with another character). On the second map, the player has a choice to save that other character or run away. If the player runs away, that variable is decreased by 5, if they save the person it goes up by 5. After the boss fight, there are 2 possible events, one if the variable totals 15 or higher and the other does not check the variable. Both are also set to be triggered after the boss fight is over. The problem I have is that it always chooses the event that doesn't check the variable. I tried changing the "bad ending" to check for the variable at 5 or so and it still chose that one. Can anyone help me with this? Let me know if you need more info. Thanks
 

poccil

Sponsor

In this case, the order in which the events are declared is important.  Consider these two events:

Event ID 1
Condition: Switch "Boss Defeated" is ON
Trigger: Autorun

Event ID 2
Condition: Switch "Boss Defeated" is ON; Variable "0001: Rep" is 15 or above
Trigger: Autorun

The game will check each event in numerical order from their IDs.  Since the first event's ID is lower, it will run simply by having the switch Boss Defeated set to ON, regardless of the variable's value.  Event 2 will not have a chance to run until event 1 is finished.  One solution is to reverse the definition of each event so that event 1 becomes event 2 and vice versa:

Event ID 1
Condition: Switch "Boss Defeated" is ON; Variable "0001: Rep" is 15 or above
Trigger: Autorun

Event ID 2
Condition: Switch "Boss Defeated" is ON
Trigger: Autorun

Another solution is to create extensions that can overcome the limitations present when defining conditions in the event system.  I have developed script-based switches for this purpose.  Such a system can be used, say, for running a script that determines whether a variable is less than a certain amount.  In my system, the condition could read: "Switch 's:$game_variables[1]<15' is ON".
 

poccil

Sponsor

That's what I didn't realize.  When creating event pages, make sure the conditions for each are more specific the higher the page number is.  Using the example above, the recommended structure is:

(More general conditions)

Event Page 1
Condition: Switch "Boss Defeated" is ON
Trigger: Autorun

(More specific conditions)

Event Page 2
Condition: Switch "Boss Defeated" is ON; Variable "0001: Rep" is 15 or above
Trigger: Autorun

As for any autorun event, however, there must be a way to stop the event from running multiple times.  To do this, you can place an event command like the following at the end of the event:

Control Self Switch: A =ON

And create a third event page that checks for the self switch:

Event Page 3
Condition: Self Switch "A" is ON
Trigger: Action Button

I hope this helps.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top