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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • 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

      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