keeping track of data

doin

New Member
Reaction score
1
is it possible to keep track of an amount of data per unit without having to create a sh**load of variables, if so, how plz...
I think it has something to do with structs, but for some reason, everytime I try to use them, the game doesn't start, so if someone would post an examlory code from the first 'till the last line from the trigger, I'd be happy...

this is the last code I tried it with
Header
JASS:
struct test
    integer a=4
    integer b=2
    integer sum
endstruct


trigger itself
JASS:
function Trig_Structtest_Actions takes nothing returns nothing
    local test a = test.create()
    set a.sum = a.a + a.b
    set uitkomst = I2S(a.sum)
    call test.destroy()
endfunction

//===========================================================================
local string uitkomst
function InitTrig_Structtest takes nothing returns nothing
    set gg_trg_Structtest = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Structtest, function Trig_Structtest_Actions )
    call DisplayTextToPlayer(Player(0),0,0,uitkomst)
endfunction


feel free to correct me if anything is wrong
 

SerraAvenger

Cuz I can
Reaction score
234
JASS:
//===========================================================================
local string uitkomst
function InitTrig_Struc


here is a small error. It needs to be
JASS:

globals
   string uitkomst
endglobals


next, the display would have been called before the other action would have even started. You'll need to invoke the DisplayTextToPlayer() function after setting the uitkomst string, so straight before the struct destruction might be a good place to call it.

hth, davey
 

doin

New Member
Reaction score
1
still won't work, when I save, and it compiles, it gives the error" line XX, test is not of a type that allows . syntax"
 

Forty

New Member
Reaction score
6
where did you declare test as struct?
/edit: i see

call test.destroy()


->

call a.destroy()

destroy is non-static
 

Viikuna

No Marlo no game.
Reaction score
265
Try
JASS:
call a.destroy()
instead of
JASS:
call test.destroy()


Edit. Damn, I was too slow :D
 

doin

New Member
Reaction score
1
still won't work, updated code is
JASS:
function Trig_Structtest_Actions takes nothing returns nothing
    local test a = test.create()
    set a.sum = a.a + a.b
    set uitkomst = I2S(a.sum)
endfunction


//===========================================================================
globals
    string uitkomst
endglobals
function InitTrig_Structtest takes nothing returns nothing
    set gg_trg_Structtest = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Structtest, function Trig_Structtest_Actions )
    call DisplayTextToPlayer(Player(0),0,0,uitkomst)
    call a.destroy()
endfunction


and the struct declaration is still in the custom script part of Newgen
 

Viikuna

No Marlo no game.
Reaction score
265
EDIT. Oh I see know what you are going to do.

you need to have a global struct

local test a cant be used outside of its own function.

EDIT. or destroy that struct inside Trig_Structtest_Actions function
 

doin

New Member
Reaction score
1
still get the start-up screen when I try to test...
EDIT:correct???
JASS:
globals
    struct test
        integer a=4
        integer b=2
        integer sum
    endstruct
endglobals

JASS:
function Trig_Structtest_Actions takes nothing returns nothing
    test a = test.create()
    set a.sum = a.a + a.b
    set uitkomst = I2S(a.sum)
endfunction


//===========================================================================
globals
    string uitkomst
endglobals
function InitTrig_Structtest takes nothing returns nothing
    set gg_trg_Structtest = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Structtest, function Trig_Structtest_Actions )
    call DisplayTextToPlayer(Player(0),0,0,uitkomst)
    call a.destroy()
endfunction
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
JASS:
function Trig_Structtest_Actions takes nothing returns nothing
    test a = test.create()
    set a.sum = a.a + a.b
    set uitkomst = I2S(a.sum)
endfunction


//===========================================================================
globals
    string uitkomst
endglobals
function InitTrig_Structtest takes nothing returns nothing
    set gg_trg_Structtest = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Structtest, function Trig_Structtest_Actions )
    call DisplayTextToPlayer(Player(0),0,0,uitkomst)
    call a.destroy()
endfunction


Should be:

JASS:
globals
    string uitkomst
endglobals

function Trig_Structtest_Actions takes nothing returns nothing
    test a = test.create()
    set a.sum = a.a + a.b
    set uitkomst = I2S(a.sum)
    call DisplayTextToPlayer(Player(0),0,0,uitkomst)
    call a.destroy()
endfunction


//===========================================================================
function InitTrig_Structtest takes nothing returns nothing
    set gg_trg_Structtest = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Structtest, function Trig_Structtest_Actions )
endfunction
 

doin

New Member
Reaction score
1
and yet again I get the startup screen, if someone would do me the pleasure of creating the working code inside a map, then I would be able to compare that one and mine and come back to say what was wrong, if it isn't too much an effort.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Are you saving before testing? Note that you can't even scroll through the code after saving, then you have to save again.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Try saving twice and then instantly hit the Test Map button without doing anything in between.
 

doin

New Member
Reaction score
1
doesn't help, I get a syntax error on the line with
JASS:
test a = test.create()

how come??
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
JASS:
    test a = test.create()


Should be

JASS:
    local test a = test.create()
 

doin

New Member
Reaction score
1
that did the trick, thx guys
EDIT: The map runs now, but it won't show the value stored in sum, or any other string if I try to use another one... Help me plz, growing a bit tired of this.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
You need to add some sort of event in your Init function. Maybe
JASS:
call TriggerRegisterPlayerChatEvent(gg_trg_Structtest, Player(0), "-test", true)


That registers the event "Player 1 (red) types chat message -test as an exact match".
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top