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 The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    Sticking with the desserts for now the latest recipe is Fried Apple Pies - https://www.thehelper.net/threads/recipe-fried-apple-pies.194297/
  • The Helper The Helper:
    Finally finding about some of the bots that are flooding the users online - bytespider apparently is a huge offender here - ignores robots.txt and comes in from a ton of different IPs

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top