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
 
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
 
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.
 
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 ><"
 
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.
 
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.
 
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...
 
well, you need a updated vJass compile (JNGP + Latest JassHelper or just JassHelper) to run it :x
 
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.
 
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 :)
 
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?
 
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.
 
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?
 
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.
 
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..
 
why you want to link then together? :p

just use the variable.. they are globals, can be used in anywhere else
 
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?
 
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 The Helper:
    Love you man so glad you are still here
  • Varine Varine:
    I live a very boring life otherwise.
  • Varine Varine:
    23AndMe is apparently looking to sell the company. I wonder what that means for all the genetic data they have. I don't have an account for The Atlantic so I can't read the rest of their news, but presumably whoever would buy the company would then have access to that, and I don't think there are any HIPPA or equivalent protections on it
  • Varine Varine:
    I'd bet it would be a treasure trove for pharmaceutical manufacturing and genetic research. I know they sold some genetic information a few years ago but they did that without identifying information attached
  • Varine Varine:
    It's be like a really boring biopunk dystopia. My TV started giving me ads when I turn it on recently (which is real fucking cool), and now I'm imagining it just being like "bioinformation says you have cancer. Get a prescription for Avastin today" and then you get connected to someone that is technically a doctor but really mostly just selling drugs to people right on your TV since they have cameras now to give you a prescription.
  • Varine Varine:
    So, buy stocks in whoever buys them would be my bet
  • Varine Varine:
    I wish I had time to keep up on things like this. My investment portfolio would probably look a bit better.
  • N Natalie the gay boss:
    So I am starting a thread.pls search how to make the teacher mad.
  • Ghan Ghan:
    Hive is 20 years old today.
  • The Helper The Helper:
    No way - holy shiznit!
  • The Helper The Helper:
    love that it is still going strong too!
  • The Helper The Helper:
    OMG I cannot handle this Natalie person I hate to do it but ban hammer activated
    +1
  • The Helper The Helper:
    I would rather not have anyone ever post then those kinds of posts
  • Varine Varine:
    lol what were they doing?
  • Varine Varine:
    3D printer is working again. Had to get a bunch of parts, cuz I forgot I kind of modded it and then never finished modding it. Turns out thermistors aren't all the same
  • Varine Varine:
    And as a result I may have gotten the hot end way too hot and caused a small fire
  • Varine Varine:
    Anyway I have a new not end and this one has the right things
  • Varine Varine:
    Although I get these really weird artifacts, I think its from my bed not being clean. Not really sure, I've seen this before though and I think cleaning the build plate fixed it. Eh, I'll figure it out, worst case scenario it rips the rest of the model off and it catches fire again
  • Varine Varine:
    I'm now realizing I could have cut out like 99% of this print and it would have been fine cuz I just need to see if a frame will fit over an LCD
  • Varine Varine:
    Oh well
  • Varine Varine:
    I'm not an engineer
  • Varine Varine:
    Although this filament is kind of expensive, I should probably be a bit more wary of that.
  • The Helper The Helper:
    I love the whole concept of 3D Printers and am very happy you have one so I can hear about them
  • The Helper The Helper:

      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