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.
 
yeah...so that how do i fix it?

Well i know that in early
 
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..
 
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
 
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?
 
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.
 
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()
 
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)
 
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
 
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 :)
 
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.
 
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?
 
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()
 
> 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.
 
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 The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      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