HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

vJASS Bugging Out

12-14-2008, 11:08 AM#1
Pyrogasm
I have no idea what's going on with this script, but it seems to be seriously fucked up:
Collapse JASS:
library Pools requires LinkedList
    //******************************************************************************************
    //* Pools by Pyrogasm (Version 3.0 12/13/2008):
    //*
    //*   Pools are lists of integers each with a 'weight' attached; the weight is relative only
    //*     to other weights within the same Pool
    //*   Pools can be useful for item drop tables, random events, scripted conversations, etc.
    //*   Because this uses table there is no limit to the number of values a pool may contain,
    //*     or a limit on how large or small the values or weights may be.
    //*
    //*   While integer pools are certainly the most common, there might be a need for a handle
    //*     or a string pool, so three default data types exist:
    //*         Pool       - stores integers
    //*         HandlePool - stores handles
    //*         StringPool - stores strings
    //*   These are created with the textmacro "Create__Pool", which can be found in the script;
    //*     should you have any need for other types of pools, feel free to use the textmacro to
    //*     create your own
    //*
    //* Usage:
    //*
    //*   Pools are structs, so you may create and destroy them like any other object
    //*   They have a few methods:
    //*     .create()   - creates a new pool (like any vJASS object)
    //*     .destroy()  - destroys the pool (like any vJASS object)
    //*     .Clone()    - creates a copy of the pool (retains all values and weights)
    //*     .GetValue() - returns a random, weighted value from the pool
    //*
    //*   And there are some methods for dealing with the values a pool contains:
    //*     .Add(V, W, B)          - adds value V with weight W to the pool; if B is true and
    //*                           the value already exists, it will be modified instead
    //*     .Remove(V)          - removes value V from the pool
    //*     .SetWeight(V, W, B) - changes the weight of V to become W, if B is true and if
    //*                           the value doesn't exist, it will be added to the Pool
    //*     .GetWeight(V)       - returns the current weight of value V; if V was not in the
    //*                           pool, this will return -666.00
    //*          
    //*   Finally, you can access some of the members of the struct on a readonly basis:
    //*     .WeightTotal  - this is the total of all the weights currently in the struct; it
    //*                     could be useful for calculating the exact chance of getting a
    //*                     specific value, for instance
    //*
    //*     
    //*  Credits to Ammorth for his LinkedList system!
    //******************************************************************************************

    globals
        private constant integer MAX_INSTANCES = 8190
        private constant integer STORAGE_MAX_INSTANCES = 8190
    endglobals

    //! textmacro Pool__Creation takes NAME, TYPE, DEFAULT
    private struct $NAME$_Storage[STORAGE_MAX_INSTANCES]
        $TYPE$ Value
        real Weight
    endstruct

    struct $NAME$[MAX_INSTANCES]
        private List LL
        readonly real WeightTotal = 0.00

//        private method GetLinkFromValue takes $TYPE$ V returns Link
//            local Link L = .LL.first
//            local $NAME$_Storage S

///            loop
//                exitwhen L == 0

//                set S = L.data
//                if S.Value = V then
//                    return L
//                endif

//                set L = L.next
//            endloop

//            return 0
//        endmethod

//        method Add takes $TYPE$ V, real W, boolean Modify returns nothing
//            local Link L = .GetLinkFromValue(V)
//            local $NAME$_Storage S = L.data

//            if W > 0.00 then
//                if L == 0 then
//                    set S = $NAME$_Storage.create()
//                    set S.Value = V
//                    set S.Weight = W
//                    set .WeightTotal = .WeightTotal+W

//                    call Link.create(.LL, S)
//                elseif Modify then
//                    set .WeightTotal = .WeightTotal+(W-S.Weight)
//                    set S.Weight = W
//                debug else
//                    debug call BJDebugMsg("|cffff0000Pools Error:|r Value already existed in $NAME$("+I2S(this)+"), and was not modified in the pool!")
//                endif
//            debug else
//                debug call BJDebugMsg("|cffff0000Pools Error:|r Weight "+R2S(W)+" is invalid. Value not added to $NAME$("+I2S(this)+")!")
//            endif
//        endmethod

//        method Remove takes $TYPE$ V returns nothing
//            local Link L = .GetLinkFromValue(V)
//            local $NAME$_Storage S

//            if L > 0 then
//                set S = L.data
//                call S.destroy()
//                call L.destroy()
//            debug else
//                debug call BJDebugMsg("|cffff0000Pools Error:|r Value does not exist in $NAME$("+I2S(this)+"), and was not removed from the pool!")
//            endif
//        endmethod

//        method SetWeight takes $TYPE$ V, real W, boolean Create returns nothing
//            local Link L = .GetLinkFromValue(V)
//            local $NAME$_Storage S = L.data

//            if W > 0.00 then
//                if L > 0 then
//                    set .WeightTotal = .WeightTotal+(W-S.Weight)
//                    set S.Weight = W
//                elseif Create then
//                    set S = $NAME$_Storage.create()
//                    set S.Value = V
//                    set S.Weight = W
//                    set .WeightTotal = .WeightTotal+W

//                    call Link.create(.LL, S)
//                debug else
//                    debug call BJDebugMsg("|cffff0000Pools Error:|r Value did not exist in $NAME$("+I2S(this)+"), and was not added to the pool!")
//                endif
//            debug else
//                debug call BJDebugMsg("|cffff0000Pools Error:|r Weight "+R2S(W)+" is invalid. "+I2S(V)+" not modified in $NAME$("+I2S(this)+")!")
//            endif
//        endmethod

//        method GetWeight takes $TYPE$ V returns real
//            local Link L = .GetLinkFromValue(V)
//            local $NAME$_Storage

//            if L > 0 then
//                S = L.data
//                return S.Weight
//            debug else
//                debug call BJDebugMsg("|cffff0000Pools Error:|r Value did not exist in $NAME$("+I2S(this)+"), weight was returned as -666.00!")
//            endif

//            return -666.00
//        endmethod

//        method GetValue takes nothing returns $TYPE$
//            local real R = GetRandomReal(0.00, .WeightTotal)
//            local integer J = 0
//            local real Check
//            local Link L = .LL.first

//            loop
//                exitwhen L == 0

//                set S = L.data
//                set R = R-S.Weight
//                if R <= 0.00 then
//                    return S.Value
//                endif

//                set L = L.next
//            endloop

//            return $DEFAULT$
//        endmethod

//        method Clone takes nothing returns $NAME$
//            local $NAME$ C = $NAME$.create()
//            local Link L = C.LL.first
//            local $NAME$_Storage S
//            local $NAME$_Storage CS

//            set C.WeightTotal = .WeightTotal

//            loop
//                exitwhen L == 0

//                set S = L.data
//                set CS = $NAME$_Storage.create()
//                set CS.Value = S.Value
//                set CS.Weight = CS.Weight
//                call Link.create(C.LL, CS)

//                set L = L.next
//            endloop

//            return C
//        endmethod

//        static method create takes nothing returns $NAME$
//            local $NAME$ P = $NAME$.allocate()

//            set P.LL = List.create()

//            return P
//        endmethod

//        method onDestroy takes nothing returns nothing
//            local Link L = LL.first
//            local Link NL
//            local $NAME$_Storage S

//            loop
//                exitwhen LN == 0

//                set S = L.data
//                call S.destroy()
//                set LN = L.next
//                call L.destroy()

//                set L = LN
//            endloop

//            call LL.destroy()
//        endmethod
    endstruct
    //! endtextmacro

    //! call runtextmacro Pool__Creation("Pool", "integer", "0")
    ///! call runtextmacro Pool__Creation("HandlePool", "handle", "H2I(V)", "null")
    ///! call runtextmacro Pool__Creation("StringPool", "string", "String2Int(V)", """")
endlibrary
Basically what happens is that this:
Collapse JASS:
//! import s:\LinkedList.j
//! import s:\Pools.j

scope F initializer Init
    globals
        Pool Whoo
    endglobals

    function Init takes nothing returns nothing
        set Whoo = Pool.create()
    endfunction
endscope
When I try to save I get the errors "Undefined type: Pool" and "Pool is not a type that allows dot syntax"

I know the import is working properly because when I review the script in the syntax error dialog, LinkedList is being imported properly and its variables and functions are being created. The global "MAX_INSTANCES" and "MAX_STORAGE_INSTANCES" are being created along with some of the other library code; however, if I scroll through the whole script I can't find any "Pool"-related variables. It's as if the textmacro just doesn't execute.


Odd, no?
12-14-2008, 11:22 AM#2
Captain Griffen
//! call runtextmacro Pool__Creation("Pool", "integer", "0")

Shouldn't that be:

//! runtextmacro Pool__Creation("Pool", "integer", "0")
12-14-2008, 11:48 AM#3
Pyrogasm
GODDAMN.

I looked at that "call" and said... "Why is there a call there" and then ignored it.
12-14-2008, 11:50 AM#4
Vexorian
wrong:
Collapse JASS:
    //! call runtextmacro Pool__Creation("Pool", "integer", "0")
    ////! call runtextmacro Pool__Creation("Pool", "integer", "0")
    ////! runtextmacro Pool__Creation("Pool", "integer", "0")