Jump to content

Using global variables as an "index for a "state machine"


Recommended Posts

Good evening everybody!

 

A while ago I asked about using quests (quest stages) as a state machine.

Somebody told me that that isn't really possible because you can't decrement quest stages.

 

So I got told to use global variables instead.

Alright, but that brings up a very big question:

 

 

For quest stages, there is a nice "event" that lets you do something when a certain quest stage is reached (OnStageSet).

But there is no such thing for global variables.

 

So how would I "do something" (in a scirpt) when a global variable reaches a certian value?

Something like "OnStageSet" but for global variables.

Link to comment
Share on other sites

If you are going to use a script to modify the value of the gobal, you could call a function directly:

StateMachineGlobal.SetValueInt(2)
MyQuestScript.StateMachine()

and write the code of your "states" in a function of a quest script:

Function StateMachine()
    If StateMachineGlobal.GetValueInt() == 1
        ;your code
    EndIf

    If StateMachineGlobal.GetValue() == 2
        ;your code
    EndIf

    If StateMachineGlobal.GetValue() == 3
        ;your code
    EndIf

   ;and so on...
EndFunction

Or use script states, calling GoToState("Seven") and then use OnBeginState event to put your code. You can check the state with GetState, or you can store the state in a property and use GetVMQuestVariable to get it as a condition function.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...