Help with TriggerRegisterPlayerChatEvent

priest170234

New Member
Reaction score
0
Hi all! I am new to JASS and a new member to this forum:)

Apparently, i started learning JASS just yesterday. So I might be unsure of almost everything.

Anyways, I am having a little problem with this:
JASS:
TriggerRegisterPlayerChatEvent( gg_trg_TRIGGER, Player(0), udg_STRING, true)


Can I use a global variable for this function? I tried but to no luck.

This is my whole trigger:

Global variables:
udg_RandomString[1] = .......
udg_RandomString[2] = .......
udg_RandomInteger = Random Integer between 1 and 2

JASS:
function Trig_TRIGGER_Actions takes nothing returns nothing
        ------ALL MY CODE HERE
endfunction

//===========================================================================
function InitTrig_TRIGGER takes nothing returns nothing
    set gg_trg_TRIGGER = CreateTrigger(  )
    set udg_STRING = udg_RandomString[udg_RandomInteger]

    call TriggerRegisterPlayerChatEvent( gg_trg_TRIGGER, Player(0), udg_STRING, true )
    call TriggerAddAction( gg_trg_TRIGGER, function Trig_TRIGGER_Actions )
endfunction


Help would be appreciated :)




EDIT (I solved it! With help from Laiev, DioD and Troll-Brain):

These triggers is to enable those maps that require to think what's the password. (Like in Impossible Map, if you played it)
Your unit enters the region, creates a random string as password. This password is 'hidden' inside the quest description. (If the player is smart to think of that he would see the password). Then the player have to type that password in order to advance to the next stage.
I didn't use GUI because it doesn't allow me to do so. (Add the Player types a string "" as an exact match)


TRIGGER ONE [Global Declaration]
JASS:
scope global initializer init

globals
    string STRING
    integer RANDOM_INTEGER
    string array RANDOM_STRING[2]
endglobals

private function init takes nothing returns nothing
    set RANDOM_STRING[0] = "lol"
    set RANDOM_STRING[1] = "lolol"
    set RANDOM_INTEGER = GetRandomInt(0,1)
    set STRING = RANDOM_STRING[RANDOM_INTEGER]
endfunction

endscope


TRIGGER TWO[PW]
JASS:
scope pw initializer onInit

private function pw_Conditions takes nothing returns boolean
    if ( not ( GetEnteringUnit() == udg_ChosenHero ) ) then
        return false
    endif
    return true
endfunction

function pw_Actions takes nothing returns nothing
    
    call DisableTrigger( GetTriggeringTrigger() )
    call IssueImmediateOrder( udg_ChosenHero, "stop" )
    call CreateQuestBJ( bj_QUESTTYPE_REQ_DISCOVERED, "PASSWORD", ( "The password is : " + STRING ), "ReplaceableTextures\\WorldEditUI\\Editor-Random-Unit.blp" )
    call EnableTrigger(gg_trg_p)
    call DisplayTextToForce( GetPlayersAll(), STRING )
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

//===========================================================================
private function onInit takes nothing returns nothing

    local trigger t = CreateTrigger()

    call TriggerRegisterEnterRectSimple( t, gg_rct_PasswordQuest )
    call TriggerAddCondition( t, Condition( function pw_Conditions ) )
    call TriggerAddAction( t, function pw_Actions )
endfunction

endscope



TRIGGER THREE [p]
JASS:
function Trig_p_Actions takes nothing returns nothing
    call DisableTrigger( GetTriggeringTrigger() )
    set udg_TempPoint[1] = GetRectCenter(gg_rct_PaswordQuestTerain)
    call SetTerrainTypeBJ( udg_TempPoint[1], 'Ydrt', -1, 1, 0 )
    call DestroyQuest( GetLastCreatedQuestBJ() )
    call DisplayTimedTextToForce( GetPlayersAll(), 5.00, "Correct" )
    call RemoveLocation(udg_TempPoint[1])
endfunction

//===========================================================================
function InitTrig_p takes nothing returns nothing
    set gg_trg_p = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent(gg_trg_p, Player(0), STRING, true) 
    call TriggerAddAction( gg_trg_p, function Trig_p_Actions )
endfunction
 

Laiev

Hey Listen!!
Reaction score
188
yes, you can but

JASS:
set udg_STRING = udg_RandomString[udg_RandomInteger]


udg_RandomInteger?


try this:

JASS:
function Trig_TRIGGER_Actions takes nothing returns nothing
        ------ALL MY CODE HERE
endfunction

//===========================================================================
function InitTrig_TRIGGER takes nothing returns nothing
    set gg_trg_TRIGGER = CreateTrigger(  )
    set udg_STRING = udg_RandomString[GetRandomInt(1, 2)] //you don't need another global for this

    call TriggerRegisterPlayerChatEvent( gg_trg_TRIGGER, Player(0), udg_STRING, true )
    call TriggerAddAction( gg_trg_TRIGGER, function Trig_TRIGGER_Actions )
endfunction


PS: really... it will be so anonymous

since when map initialize, your trigger will register just one event based on a random variable (?)

sorry but this is stupid lol
 

priest170234

New Member
Reaction score
0
Thanks for the reply.
You see, the purpose is to create a random string message.
Lets say I have this unit that enters this region. Then a random string is generated.
This is then shown on the quest that is created. The player is supposed to type that random string.
I tried using your code but its the same effect. I typed anything and it just executed the action.
 

Laiev

Hey Listen!!
Reaction score
188
oh, so you'll need the global variable in the array :p

make sure to initialize that globals....

other way to do this is:

JASS:
scope Something initializer onInit

globals
    string STRING
    string array RANDOM_STRING[2] //chance the 2 for how much variable will be
    integer RANDOM_INTEGER
endglobals

private function Actions takes nothing returns nothing
        //------ALL MY CODE HERE
endfunction

private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0

    set RANDOM_STRING[1] = "something 1"
    set RANDOM_STRING[2] = "something 2"
    set RANDOM_INTEGER = GetRandomInteger(1, 2)

    set STRING = RANDOM_STRING[RANDOM_INTEGER]

    loop
        exitwhen i > 11
        call TriggerRegisterPlayerChatEvent(t, Player(i), STRING, true)
        set i = i + 1
    endloop
    //with the loop above, the event will be registred for all players, not only player 0 (red)
    call TriggerAddAction(t, function Actions)
endfunction
endscope


PS: free-hand, sorry if some syntax error ><"
 

DioD

New Member
Reaction score
57
lulz.

RTFM, event register to value at moment of registration, if you change global later, it wont affect trigger.
If you register again, other events will stay.
If you recreate trigger, it may work, but any thread running by this trigger will result in major memory leak.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
But you can use that :

JASS:
call TriggerRegisterPlayerChatEvent(t, Player(i), &quot;&quot;, false) // any string will fire the event


And a condition trigger, here you can use a global string and change his value later in game, it will affect the result of the trigger condition evaluation.
 

priest170234

New Member
Reaction score
0
oh, so you'll need the global variable in the array :p

make sure to initialize that globals....

other way to do this is:

JASS:
scope Something initializer onInit

globals
    string STRING
    string array RANDOM_STRING[2] //chance the 2 for how much variable will be
    integer RANDOM_INTEGER
endglobals

private function Actions takes nothing returns nothing
        //------ALL MY CODE HERE
endfunction

private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0

    set RANDOM_STRING[1] = &quot;something 1&quot;
    set RANDOM_STRING[2] = &quot;something 2&quot;
    set RANDOM_INTEGER = GetRandomInteger(1, 2)

    set STRING = RANDOM_STRING[RANDOM_INTEGER]

    loop
        exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent(t, Player(i), STRING, true)
        set i = i + 1
    endloop
    //with the loop above, the event will be registred for all players, not only player 0 (red)
    call TriggerAddAction(t, function Actions)
endfunction
endscope


PS: free-hand, sorry if some syntax error ><"

I don't understand your code. I copied and compiled with a whole lots of errors:( Sorry I am not really sure because I am really new to JASS...
 

Laiev

Hey Listen!!
Reaction score
188
well, you need a updated vJass compile (JNGP + Latest JassHelper or just JassHelper) to run it :x
 

priest170234

New Member
Reaction score
0
Edit

Okay, I decided to re-iterate what problem I am having.

What I want is:
A unit enters this region, a random string is produced.
Then the player is supposed to type this to continue.

What I have in my triggers is this:

TRIGGER ONE
At map initialization,
JASS:
set udg_RANDOMINT = random integer between 1 and 2
set udg_RANDOMSTRING[1] = lol
set udg_RANDOMSTRING[2] = lolol
set udg_STRING = udg_RANDOMSTRING[udg_RANDOMINT]



TRIGGER TWO
The unit enters this region, then actions:
JASS:
call DisplayTimedTextToForce( GetPlayersAll(), 5.00, udg_STRING )

Turn on TRIGGER THREE

TRIGGER THREE
Player suppose to type the udg_STRING to continue on.
I then used
JASS:
call TriggerRegisterPlayerChatEvent( gg_trg_TRIGGER, Player(0), udg_STRING, true )


But when i type anything, it just executed the actions I wanted.
 

Laiev

Hey Listen!!
Reaction score
188
yes, you can (but i think you'll need to upgrade the jasshelper)

if you type anything and the function execute, is because you're having some problem with variable STRING, since it ins't set'ed, why? idk, need to see whats happen... and the 'default' value of variable string is "", is exactly what Troll-Brain said

probably is because the function initialize before the set of variable :)
 

priest170234

New Member
Reaction score
0
yes, you can (but i think you'll need to upgrade the jasshelper)

if you type anything and the function execute, is because you're having some problem with variable STRING, since it ins't set'ed, why? idk, need to see whats happen... and the 'default' value of variable string is "", is exactly what Troll-Brain said

probably is because the function initialize before the set of variable :)

So is there anyway I can set the variable before it initializes the function?:)

I compiled the file, with one problem.
Invalid Scope name.

How do I resolve that?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Laiev's code has only one error.
GetRandomInteger -> GetRandomInt.

You can write a scope/library in an empty trigger converted in full jass (custom script), that's probably your error, i mean i suppose you pasted it somewhere else.
In fact you can also put it in the header of the map (custom script window when you click on the title of the map), but for readability it's not recommended.

PS : Technically since he used the size "2" for the string global array he should use the index "0" and "1" but that really doesn't matter here.
 

priest170234

New Member
Reaction score
0
Laiev's code has only one error.
GetRandomInteger -> GetRandomInt.

You can write a scope/library in an empty trigger converted in full jass (custom script), that's probably your error, i mean i suppose you pasted it somewhere else.
In fact you can also put it in the header of the map (custom script window when you click on the title of the map), but for readability it's not recommended.

PS : Technically since he used the size "2" for the string global array he should use the index "0" and "1" but that really doesn't matter here.

Sorry for the stupid question:
What's a scope?
Can't I just use the normal different functions?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
A scope is a a block of code, a way to keep your code clean and organized.
Well, i fail to explain what's exactly a scope, i suggest you to read the jasshelper documentation included in the JassNewGenPack.
 

priest170234

New Member
Reaction score
0
A scope is a a block of code, a way to keep your code clean and organized.
Well, i fail to explain what's exactly a scope, i suggest you to read the jasshelper documentation included in the JassNewGenPack.

Okay. The code

JASS:
scope Something initializer onInit

globals
    string STRING
    string array RANDOM_STRING[2] //chance the 2 for how much variable will be
    integer RANDOM_INTEGER
endglobals

private function Actions takes nothing returns nothing
        //------ALL MY CODE HERE
endfunction

private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0

    set RANDOM_STRING[1] = &quot;something 1&quot;
    set RANDOM_STRING[2] = &quot;something 2&quot;
    set RANDOM_INTEGER = GetRandomInt(1, 2)

    set STRING = RANDOM_STRING[RANDOM_INTEGER]

    loop
        exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent(t, Player(i), STRING, true)
        set i = i + 1
    endloop
    //with the loop above, the event will be registred for all players, not only player 0 (red)
    call TriggerAddAction(t, function Actions)
endfunction
endscope

worked and I am glad. However, that is not what I want for all. This is just one trigger where the player have to type either 'something1' or 'something2'.

What I want is a unit enters a region, then creates the string array like that one, and shows that message in the quest description.
It then opens up the trigger where the player must type the 'something1' or
something2'. Apparently I am stuck linking both triggers together..
 

Laiev

Hey Listen!!
Reaction score
188
why you want to link then together? :p

just use the variable.. they are globals, can be used in anywhere else
 

priest170234

New Member
Reaction score
0
Not link, but in two separate triggers. Trigger one is for unit enters region and create the strings and show quest. And to enable trigger two.
Trigger two is the player types the string.
So do I create the global variables in trigger one?
And excess in trigger two?

If so, how?

And is the global variables the same as the udg_Variable thing in variable editor?
 

Laiev

Hey Listen!!
Reaction score
188
JASS:
scope A
globals
    string A = &quot;A&quot;
endglobals
endscope

scope B
function Test takes nothing returns nothing
    call BJDebugMsg(A)
endfunction
endscope


in this example, scope A is a trigger, and scope B is another trigger... you can access the global in anytrigger

yes, they are globals... like gui but don't need the prefix udg_
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top