• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] Saving in Table

Status
Not open for further replies.
Level 5
Joined
Sep 16, 2008
Messages
47
i got simple question. Here is code that i wrote to ask, it's just quick made example.

Let's say in the loop onCast i save some real that i use in CTLExpire.

But how can i change this value?

if i write:
JASS:
set a = a + 10

I need this value to change every loop.

it's like. In loop 1 it's 50 but in loop 2 it's 100, in loop 3 it's 150
JASS:
set distance = distance + 50

JASS:
scope spell

    globals
        private constant integer SPELL_CODE = 'A000'
    endglobals
    
    private struct spell
    
        private static unit array caster
        
        private static integer array i
        
        static Table array tab
    
        implement CTL
        
            local real index = 0
            local real amount = 10
            local real a
        
        implement CTLExpire
        
            loop
            
                set a = tab[this].real[index]
            
                set index = index + 1
            
                exitwhen index == amount
                
            endloop
            
            set i[this] = i[this] - 1
            
            if i[this] == 0 then
            
                set caster[this] = null
                call destroy()
            
            endif
        
        implement CTLNull
        implement CTLEnd
    
        private static method onCast takes nothing returns nothing
        
            local thistype this = create()
            
            local real index = 0
            local real amount = 10
            local real a = 0
            
            set caster[this] = GetTriggerUnit()
            
            set i[this] = 50
            
            set tab[this] = Table.create()
            
            loop
            
                set a = a + 10
                
                set tab[this].real[index] = a
            
                set index = index + 1
            
                exitwhen index == amount
                
            endloop
        
        endmethod
    
        private static method onInit takes nothing returns nothing
            call RegisterSpellEffectEvent(SPELL_CODE,function thistype.onCast)
        endmethod
    
    endstruct

endscope
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
You are using CTL incorrect.
Locals have to be initialized below CTLExpire. Otherwise i.e index will
still have the same value set, as it was in the end of the previous instance.

if not clear: CTL copies a linked list data structure +creator/destructor into
your struct.
 
Status
Not open for further replies.
Top