playMaker

Author Topic: Global bool test or send event?  (Read 1183 times)

neuroTrophy

  • Playmaker Newbie
  • *
  • Posts: 1
Global bool test or send event?
« on: August 14, 2017, 01:01:53 PM »
Hello,
I have an "enemy" with three child gameobjects, each with its own trigger collider (each set at a different radius) and its own FSM. The parent also has an FSM that I want to use to control its behavior (simple movement). My goal is to have it so that depending on which "zone" the player is in (as determined by 3 triggers), the enemy behaves differently. Currently, I have it set up to where once the first collider is triggered, an event is sent which transitions the sibling FSM (via global transition) to begin monitoring the next inner collider, and so on. What I want to know is, what would you recommend I do within the parent FSM to monitor which "zone", and therefore which behavior, to engage in. I could send other events from the children, with global transitions in the parent FSM, OR, I could store global bools and perform bool tests in the parent FSM. I am concerned about performing a bool check every frame, though I may be wrong. How would you implement this?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Global bool test or send event?
« Reply #1 on: August 14, 2017, 08:40:09 PM »
HI,
The bool check is a minimal performance difference,
But your send event would send only once and would be cleaner.
if you would use bools you might need to run 2 bool test on each 'zone'

also if you can, always try to avoid global variables.
Quote
A global variable means that you have a variable that anybody (Also Hackers) can access and change from anywhere in code and is always in memory.