Struct problem. About using timer.

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
JASS:
//Here is an example...

scope Test
    private struct Struct
        private timer t
        private real r

        private static method M1 takes nothing returns nothing //Needs to be static because of the timer.
            local Struct this //I need this to have my data.

            call BJDebugMsg("1") //This message seems to be showing...

            call BJDebugMsg(R2S(.r)) //This message tell always0.

            call BJDebugMsg("2") //While this one, does not...
        endmethod

        private static method onInit takes nothing returns nothing
            local Struct this = Struct.allocate()
            set .t = CreateTimer()
            set .r = GetRandomReal(0,1000)

            call TimerStart(.t,.03125,true,function Struct.M1)
        endmethod
    endstruct
endscope

//I'm sure that .r is the prob, so how to fix this?
 

Azlier

Old World Ghost
Reaction score
461
Erm... no. This is why we have timer systems, you know.
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
It doesn't work at all, it's a different instance of the struct. Values won't be stored.

JASS:
//This totally works, it shows the message.  I got the latest jasshelper
scope Test
    private struct Struct
        private timer t
        private real r = 0.

        private static method M1 takes nothing returns nothing
            local Struct this = Struct.create()

            set .r = GetRandomReal(0,1000)

            call BJDebugMsg(R2S(.r))
        endmethod

        private static method onInit takes nothing returns nothing
            local Struct this = Struct.allocate()
            set .t = CreateTimer()
            set .r = 0

            call TimerStart(.t,.03125,true,function Struct.M1)
        endmethod
    endstruct
endscope
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
JASS:

//This totally works, it shows the message.  I got the latest jasshelper
scope Test

Did you ever even try to see if the same struct was being passed from onInit to M1?

Try this instead:
JASS:
scope Test
    private struct Struct
        private timer t
        private real r = 0.

        private static method M1 takes nothing returns nothing
            local Struct this = Struct.create()

            call BJDebugMsg(R2S(.r)) //If this is 0, it's passing a new struct.  If it's 6, it's passing the other struct.
        endmethod

        private static method onInit takes nothing returns nothing
            local Struct this = Struct.allocate()
            set .t = CreateTimer()
            set .r = 6 //So that we know that actual data is being used

            call TimerStart(.t,.03125,true,function Struct.M1)
        endmethod
    endstruct
endscope
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
did you ever even try to see if the same struct was being passed from oninit to m1?

Try this instead:
JASS:
scope test
    private struct struct
        private timer t
        private real r = 0.

        Private static method m1 takes nothing returns nothing
            local struct this = struct.create()

            call bjdebugmsg(r2s(.r)) //if this is 0, it's passing a new struct.  If it's 6, it's passing the other struct.
        Endmethod

        private static method oninit takes nothing returns nothing
            local struct this = struct.allocate()
            set .t = createtimer()
            set .r = 6 //so that we know that actual data is being used

            call timerstart(.t,.03125,true,function struct.m1)
        endmethod
    endstruct
endscope
0

But If I will remove [ljass]struct.create()[/ljass], It will not continue the remaining trig. Yeah, struct.create() is wrong. So, what to use?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
0

But If I will remove [ljass]struct.create()[/ljass], It will not continue the remaining trig. Yeah, struct.create() is wrong. So, what to use?

This is why we have timer systems, you know.

This.

Timer Systems exist so that you can pass data (such as a struct instance) to a method. Trying looking up KT2, Timer32, or Timer Utils. ;)
 
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