• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Issue with data retrieval from an object

Status
Not open for further replies.
Level 2
Joined
Aug 16, 2018
Messages
11
My problem is that when I set a variable like set udg_MaxLevel = UnitData[udg_UnitID].maxLevel it sets udg_MaxLevel to 0 when it should set it to 5.

JASS:
library UnitCustoms

    struct UnitTypeData
        integer unitTypeID
        integer experience
        integer maxLevel
        integer numOfDrops
        integer array itemsToDrop[1]
        integer array dropChances[1]
        static UnitTypeData array unitTypeDataMap
       
        static method operator [] takes integer v returns thistype
           return unitTypeDataMap[v]
        endmethod
       
        static method create takes integer unittypeid, integer experience, integer maxLevel returns thistype
            local thistype this = thistype.allocate()
            set unitTypeDataMap[unittypeid] = this
            set .unitTypeID = unittypeid
            set .experience = experience
            set .maxLevel = maxLevel
            set .numOfDrops = 0
            return this
        endmethod
   
        method addItemDrop takes integer ite, integer dropChance returns nothing
            set .itemsToDrop[this.numOfDrops] = ite
            set .dropChances[this.numOfDrops] = dropChance
            set .numOfDrops = .numOfDrops + 1
        endmethod
    endstruct
endlibrary

This initializes the object:

JASS:
scope SetupUnitCustoms initializer Initialize


    private function Initialize takes nothing returns nothing

        //Wolf
        call UnitTypeData.create('n004', 25, 5)
        //Wolf Pelt
        call UnitTypeData['n004'].addItemDrop('I003', 1000)

    endfunction

endscope
 
Last edited:
You would need to show your example code, too. You can print a debug message to ensure the value is set, but it looks like it should work.
I would rename a bit, UnitData -> UnitTypeData, uid -> unitType, and also index is confusing, maybe unit unitTypeDataMapping or what ever.
In Array you declare [size] which is 1. It's effectively not different from a normal scalar variable.
You can use [code=jass] code [/code] tags for jass code.
 
Level 2
Joined
Aug 16, 2018
Messages
11
You would need to show your example code, too. You can print a debug message to ensure the value is set, but it looks like it should work.
I would rename a bit, UnitData -> UnitTypeData, uid -> unitType, and also index is confusing, maybe unit unitTypeDataMapping or what ever.
In Array you declare [size] which is 1. It's effectively not different from a normal scalar variable.
You can use [code=jass] code [/code] tags for jass code.
I'll make those changes and I was wondering how to do the jass thing for code thank you. What exactly do you mean by example code? Also I set the size of the arrays because it said it was expecting a size
 
Last edited:
Level 2
Joined
Aug 16, 2018
Messages
11
I actually figured out my problem and it was through subtracting 'n000' from unitTypeID because the integer ID of a unittype is higher than the maximum elements of an array, this could be useful for other people trying to do this.
 
The way you register drops wont work. vJass doesnt allow array members beyond the max array size so everything after the first registered drop will not work with an array size of 1.
You need to define a maximum array size that will be sufficient for your system.

Remember that the array size within a struct limits the number of available struct instances allocated. This is why you have to initialize the array size in the first place.
For example: if you want an array size of 20, you are limited to 8190/20 = 495 struct instances.
If that is not enough for you (it should be in most cases), you should implement a table instead.

As an alternative, you might want to implement drops as a stack or linked list data type to get rid of the array.
 
Last edited:
Status
Not open for further replies.
Top