Struct

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Greetz Everyone,

Well, this thread is also comes with question related to vjass syntax...My VJASS thread was a messy....and i decided to start a new thread to overcome..

Now here is my problem....i had 3 trigger with the same purpose...but only the trigger that uses struct fail....any would help?

This is the STRUCT METHODED trigger
JASS:
struct words
string entered = ""
trigger Test2
endstruct

globals
words Gword
endglobals

function test2act takes nothing returns nothing
local words CS2 = Gword
local string xx = ""
local integer start = 1
set xx = CS2.entered
loop
exitwhen start >5
call DisplayTimedTextToPlayer(Player(0), 0,0,5,xx)
set start = start +1
endloop
set xx = ""
call Gword.destroy()
call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Trig_Test1_Actions takes nothing returns nothing
local words CS = words.create()
set CS.Test2 = CreateTrigger()
set CS.entered = GetEventPlayerChatString()
set Gword = CS
call TriggerAddAction(CS.Test2, function test2act)
call TriggerExecute(CS.Test2)
endfunction

//===========================================================================
function InitTrig_Test1 takes nothing returns nothing
    set gg_trg_Test1 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Test1, Player(0), "struct", true )
    call TriggerAddAction( gg_trg_Test1, function Trig_Test1_Actions )
endfunction


This is the GLOBAL METHODED trigger
JASS:
globals
string entered2
trigger Test22
endglobals

function test2act takes nothing returns nothing
local integer start = 1
loop
exitwhen start >5
call DisplayTimedTextToPlayer(Player(0), 0,0,5,entered2)
set start = start +1
endloop
call DisableTrigger(GetTriggeringTrigger())
call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Trig_Test1_Actions takes nothing returns nothing
set Test22 = CreateTrigger()
call DisableTrigger(Test22)
set entered2 = GetEventPlayerChatString()
call TriggerAddAction(Test22, function test2act)
call TriggerExecute(Test22)
endfunction

//===========================================================================
function InitTrig_Test2 takes nothing returns nothing
    set gg_trg_Test2 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Test2, Player(0), "struct", true )
    call TriggerAddAction( gg_trg_Test2, function Trig_Test1_Actions )
endfunction


This is LOCAL HANDLES VARS METHODED trigger
JASS:
function test2act takes nothing returns nothing
local timer t = GetExpiredTimer()
local string enter = GetHandleString(t, "Ent")
local integer start = 1
loop
exitwhen start >5
call DisplayTimedTextToPlayer(Player(0), 0,0,5,enter)
set start = start +1
endloop
call FlushHandleLocals(t)
call DestroyTimer(t)
set t = null
endfunction

function Trig_Test1_Actions takes nothing returns nothing
local string entered3 = GetEventPlayerChatString()
local timer t = CreateTimer()
call SetHandleString(t, "Ent", entered3)
call TimerStart(t, 0.1, false, function test2act)
endfunction

//===========================================================================
function InitTrig_Test3 takes nothing returns nothing
    set gg_trg_Test3 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Test3, Player(0), "struct", true )
    call TriggerAddAction( gg_trg_Test3, function Trig_Test1_Actions )
endfunction


Now all those 3 trigger works as i want...but there is still question down there....see the last post of this thread.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
yeah...so that how do i fix it?

Well i know that in early
 
Reaction score
456
Well.. You could make a global words variable..

JASS:
struct words
    string entered = ""
    trigger Test2
endstruct

globals
    words words_struct   
endglobals

function test2act takes nothing returns nothing
    local words CS = words_struct
    local string xx = ""
    local integer start = 1
    set xx = CS.entered
    loop
        exitwhen start >5
        call DisplayTimedTextToPlayer(Player(0), 0,0,5,xx)
        set start = start +1
    endloop
    set xx = ""
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Trig_Test1_Actions takes nothing returns nothing
    local words CS = words.create()
    set CS.Test2 = CreateTrigger()
    set CS.entered = GetEventPlayerChatString()
    call TriggerAddAction(CS.Test2, function test2act)
    set words_struct = CS
    call TriggerExecute(CS.Test2)
endfunction

//===========================================================================
function InitTrig_Test1 takes nothing returns nothing
    set gg_trg_Test1 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Test1, Player(0), "struct", true )
    call TriggerAddAction( gg_trg_Test1, function Trig_Test1_Actions )
endfunction


And some time, you should destroy it..
 

substance

New Member
Reaction score
34
JASS:
set Test22 = CreateTrigger()
call DisableTrigger(Test22)

Well, that would explain why that global method didnt work =p. Also, you should work on your indenting (spacing) because it makes it easier for us to read. Also, you shouldnt use triggeractions, instead use conditions.

And I dunno what the hell Uberplayer is doing in what he pasted, but the idea is that you know to set the struct to a global in order to access the struct from one function to another. Either that or attatch it somehow.

Hopefully this is a little easier to follow
JASS:
struct STRUCT_NAME
    string STRUCT_VARIABLE = ""
endstruct

globals
    STRUCT_NAME GLOBAL_STRUCT
endglobals

function test2act takes nothing returns nothing
 local integer start = 1
    loop
       exitwhen start >5
       call DisplayTimedTextToPlayer(Player(0), 0,0,5,GLOBAL_STRUCT.VARIABLE)
       set start = start +1
    endloop
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Trig_Test1_Actions takes nothing returns nothing
    set GLOBAL_STRUCT.STRUCT_VARIABLE = GetEventPlayerChatString()
    //whatever
endfunction
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
LoL??

The global method did work for me...it is only the struct method didnt work for me....though...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lawl? how to declare a global struct?
I didnt read it in teh manual...
JASS:
call DisplayTimedTextToPlayer(Player(0), 0,0,5,GLOBAL_STRUCT.VARIABLE) //Arent this to be This ? :

call DisplayTimedTextToPlayer(Player(0), 0,0,5,GLOBAL_STRUCT.STRUCT_VARIABLE) //or i am wrong?


>>How to destroy a globalized struct?
 
Reaction score
456
In this example:

JASS:
struct words
    string entered = ""
    trigger Test2
endstruct

globals
    words words_struct   
endglobals

function test2act takes nothing returns nothing
    local words CS = words_struct
    local string xx = ""
    local integer start = 1
    set xx = CS.entered
    loop
        exitwhen start >5
        call DisplayTimedTextToPlayer(Player(0), 0,0,5,xx)
        set start = start +1
    endloop
    set xx = ""
    call CS.destroy()
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Trig_Test1_Actions takes nothing returns nothing
    local words CS = words.create()
    set CS.Test2 = CreateTrigger()
    set CS.entered = GetEventPlayerChatString()
    call TriggerAddAction(CS.Test2, function test2act)
    set words_struct = CS
    call TriggerExecute(CS.Test2)
endfunction

//===========================================================================
function InitTrig_Test1 takes nothing returns nothing
    set gg_trg_Test1 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Test1, Player(0), "struct", true )
    call TriggerAddAction( gg_trg_Test1, function Trig_Test1_Actions )
endfunction


But I have no idea when you want it to be destroyed.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
in your example... "words_struct" does not need to be destroy?

Edit:
JASS:
struct words
string entered = ""
trigger Test2
endstruct

globals
words Gword
endglobals

function test2act takes nothing returns nothing
local words CS2 = Gword
local string xx = ""
local integer start = 1
set xx = CS2.entered
loop
exitwhen start >5
call DisplayTimedTextToPlayer(Player(0), 0,0,5,xx)
set start = start +1
endloop
set xx = ""
call Gword.destroy()
call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Trig_Test1_Actions takes nothing returns nothing
local words CS = words.create()
set CS.Test2 = CreateTrigger()
set CS.entered = GetEventPlayerChatString()
set Gword = CS
call TriggerAddAction(CS.Test2, function test2act)
call TriggerExecute(CS.Test2)
endfunction

//===========================================================================
function InitTrig_Test1 takes nothing returns nothing
    set gg_trg_Test1 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Test1, Player(0), "struct", true )
    call TriggerAddAction( gg_trg_Test1, function Trig_Test1_Actions )
endfunction

Well...now the trigger works...
But why, when i add in "call CS.destroy()" or "call CS2.destroy()" it will shows me double free of type words??

If i dont destroy it...CS and CS2 will be floating as a leak??
Is the global struct being destroy in this way?call Gword.destroy()
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
A nice way to pass on a struct without globals is by using a SetHandleInt (usually timer or group handle)

Anyhow: I don't see why you'd use structs here though.


By the way, the reason you didn't get any struct data in your called function is because you didn't tell the function to "read" the instance of the struct you created.

JASS:
local STRUCT_NAME STRUCT_INSTANCE_NAME = STRUCT_NAME( STRUCT_INTANCE )

or

local t = GetExpiredTimer()
local words <name you will call struct in this function> = words( GetHandleInt(t,"string you used to set the handle in other function") )


where you would pass the struct locally in the other function like this:

JASS:
local t = CreateTimer()
local words TriggerNameAndEnteredChatString= words.create()
call SetHandleInt(t,"string you used to set the handle in other function", TriggerNameAndEnteredChatString)
call TimerStart(t, 0.00, false, function test2act)
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
aw...magentix...if i uses your way...
Why not i fully use local handle's method as i posted on the 1st post?

Yours is even more complicated.

>>I don't see why you'd use structs here though
To learn struct
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
aw...magentix...if i uses your way...
Why not i fully use local handle's method as i posted on the 1st post?

Yours is even more complicated.

>>I don't see why you'd use structs here though
To learn struct

Well, if you use just handles, you have to transfer -everything- over and over.

If you use structs, you only have to transfer ONE thing, namely the struct.


When having to transfer more than one thing, (let alone ten or twenty) structs are the way to go for me :)
 
Reaction score
456
There is no need to attach a structure to a handle. Why would you do that as you can use one simple global structure array and a integer which is to count total structure arrays?

And in another trigger just loop through every structure in that array and do what ever you like to do with them inside that loop.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
There is no need to attach a structure to a handle. Why would you do that as you can use one simple global structure array and a integer which is to count total structure arrays?

And in another trigger just loop through every structure in that array and do what ever you like to do with them inside that loop.

Well, I didn't thought of doing it that way, but isn't there a limit of ~8000 this way?
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
well...stop argueing...just reply this
But why, when i add in "call CS.destroy()" or "call CS2.destroy()" it will shows me double free of type words??

If i dont destroy it...CS and CS2 will be floating as a leak??
Is the global struct being destroy in this way?call Gword.destroy()
 

SFilip

Gone but not forgotten
Reaction score
634
> just loop through every structure in that array
:eek:
This can easily get slower than attaching.
And structs are already limited to having 8191 instances BTW.

> when i add in "call CS.destroy()" or "call CS2.destroy()" it will shows me double free of type words
Because both CS and CS2 are absolutely the same as GWord.
CS2 = Gword <- this doesn't copy the contents of GWord into CS2. It just makes them both point to the same thing. If you want an actual copy then using methods might be a good idea.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
OMG !!-.-

>>this doesn't copy the contents of GWord into CS2
So as my example...i would just pick either:
JASS:
1.call CS.destroy()
2.call CS2.destroy()
3.call Gword.destroy()

would do?

>>If you want an actual copy then using methods might be a good idea
W*F you... You introduce another trouble to me...T.T
Last time someone introduce scope...then struct...now it comes with method...

Damn, what is method?
 
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