• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Global variable not being changed?

Status
Not open for further replies.
Level 2
Joined
Jun 18, 2017
Messages
6
Hello, moving straight to the issue:
Typing -cam <camera> should set global camera value to <camera> and it certainly does, but after typing -cam fix the debug message appears.
What do I misunderstand?

JASS:
globals
    player cameraPlayer
    real camera = 0
endglobals

function Camera_t takes nothing returns boolean
    set cameraPlayer = GetTriggerPlayer()
    set camera = S2R(SubString(GetEventPlayerChatString(),5,9))
    call CameraSet()
    return true
endfunction
function Camera_typ takes nothing returns boolean
    if camera == 0 then
        call BJDebugMsg("Cam = 0!")
    endif
    return true
endfunction
//===========================================================================
function InitTrig_Camera takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local trigger typ = CreateTrigger( )
    local integer index = 0
    loop
        call TriggerRegisterPlayerChatEvent(t,Player(index),"-cam ",false)
        call TriggerRegisterPlayerChatEvent(typ, Player(index),"-cam fix",true)
        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition( t, Condition(function Camera_t)  )
    call TriggerAddCondition( typ, Condition(function Camera_typ) ) 
    set typ = null
    set t = null
endfunction
 
There are two triggers registrated to a chat event:
  • trigger 1: "-cam" + x (anything)
  • trigger 2: "-cam fix"
You type "-cam 1" and only trigger 1 is fired. real camera becomes here "1".

You now type "-cam fix", and what you expect now is that real camera is still "1".
But what happens instead is that trigger 1 gets fired at first, so real camera gets re-assigned to "fix", so it just becomes 0 (default value), as it's not a valid number.
When trigger 2 is fired, the camrea value was already set to "0" and so the debug message appears.

What would fix this is having only 1 trigger with the chat event, and handlig the cases with help of if-blocks.
 
Status
Not open for further replies.
Top