- Joined
- Aug 9, 2006
- Messages
- 2,384
Hello,
I am currently creating a resource system for my AoS map with vJASS.
It is supposed to use a hashtable in a library to store custom "resources" (like mana and energy and such) with reference to the unit that "owns" this resource.
This is the code for the system:
It lets me compile just fine with just this code in the map header.
But when I try to call the function in my code:
to add a resource called "Nova Sparks" to "udg_u_ResourceTempUnit" (unit variable in world editor) with minimum value 0 and maximum value 0 and no decay.
The error is: SetUnitResource is not defined, and after that I get tons of errors from the library (pretty much everything errors).
I have vJASS activated in the trigger editor.
I really have no clue what the problem is.
Can somebody help me?
I am currently creating a resource system for my AoS map with vJASS.
It is supposed to use a hashtable in a library to store custom "resources" (like mana and energy and such) with reference to the unit that "owns" this resource.
This is the code for the system:
Code:
library ResourceManagementSystem
globals
private hashtable htData
private timer tIntervalTimer
private group gResourceGrouping
// Configuration for Standard Interval
private real StandardInterval = 1
endglobals
private keyword Initialization
struct ResourceProfile
public string sResourceName
public real iCurrentValue
public real iMaximumValue
public real iMinimumValue
public boolean bDecayEnabled
public real iDecayAmount
public real iDecayInterval
endstruct
private function AdjustResource takes ResourceProfile rpResource, real iValue returns real
if iValue < rpResource.iMinimumValue then
set iValue = rpResource.iMinimumValue
endif
if iValue > rpResource.iMaximumValue then
set iValue = rpResource.iMaximumValue
endif
return iValue
endfunction
private function ResourceDecayTick takes nothing returns nothing
local timer tTemp = GetExpiredTimer()
local group gTemp = CreateGroup()
local integer iHandle
local unit uTemp
local ResourceProfile rpLoadedStruct
call GroupAddGroup(gResourceGrouping,gTemp)
loop
set uTemp = FirstOfGroup(gTemp)
exitwhen uTemp == null
set iHandle = GetHandleId(uTemp)
set rpLoadedStruct = LoadInteger(htData,0,iHandle)
if rpLoadedStruct.bDecayEnabled then
set rpLoadedStruct.iCurrentValue = rpLoadedStruct.iCurrentValue - ( ( StandardInterval / rpLoadedStruct.iDecayInterval ) * rpLoadedStruct.iDecayAmount )
set rpLoadedStruct.iCurrentValue = AdjustResource(rpLoadedStruct, rpLoadedStruct.iCurrentValue)
endif
call GroupRemoveUnit(gTemp,uTemp)
endloop
endfunction
public function GetUnitCurrentResource takes unit uTargetUnitIn returns ResourceProfile
local integer iHandle = GetHandleId(uTargetUnitIn)
local ResourceProfile rpLoadedStruct = LoadInteger(htData,0,iHandle)
return rpLoadedStruct
endfunction
public function SetUnitCurrentResource takes unit uTargetUnitIn, ResourceProfile rpNewResourceIn returns nothing
local integer iHandle = GetHandleId(uTargetUnitIn)
local ResourceProfile rpLoadedStruct = LoadInteger(htData,0,iHandle)
call rpLoadedStruct.destroy()
call SaveInteger(htData,0,iHandle,rpNewResourceIn)
endfunction
public function AddUnitCurrentResourceValue takes unit uTargetUnitIn, real iAddedValue returns real
local integer iHandle = GetHandleId(uTargetUnitIn)
local ResourceProfile rpLoadedStruct = LoadInteger(htData,0,iHandle)
set rpLoadedStruct.iCurrentValue = rpLoadedStruct.iCurrentValue + iAddedValue
set rpLoadedStruct.iCurrentValue = AdjustResource(rpLoadedStruct, rpLoadedStruct.iCurrentValue)
return rpLoadedStruct.iCurrentValue
endfunction
public function GetUnitResourceCurrentValue takes unit uTargetUnitIn returns real
local integer iHandle = GetHandleId(uTargetUnitIn)
local ResourceProfile rpLoadedStruct = LoadInteger(htData,0,iHandle)
return rpLoadedStruct.iCurrentValue
endfunction
public function SetUnitResource takes unit uTargetUnitIn, string sResourceNameIn, real iMinimumValueIn, real iMaximumValueIn, boolean bDecayEnabledIn, real iDecayAmountIn, real iDecayIntervalIn returns boolean
local ResourceProfile rpLoadedStruct
if IsUnitInGroup(uTargetUnitIn, gResourceGrouping) then
return false
endif
call GroupAddUnit(gResourceGrouping, uTargetUnitIn)
set rpLoadedStruct = ResourceProfile.create()
set rpLoadedStruct.sResourceName = sResourceNameIn
set rpLoadedStruct.iMinimumValue = iMinimumValueIn
set rpLoadedStruct.iMaximumValue = iMaximumValueIn
set rpLoadedStruct.bDecayEnabled = bDecayEnabledIn
set rpLoadedStruct.iDecayAmount = iDecayAmountIn
set rpLoadedStruct.iDecayInterval = iDecayIntervalIn
set rpLoadedStruct.iCurrentValue = iMinimumValueIn
call SaveInteger(htData,0,GetHandleId(uTargetUnitIn),rpLoadedStruct)
return true
endfunction
private module Initialization
private static method onInit takes nothing returns nothing
set htData = InitHashtable()
set gResourceGrouping = CreateGroup()
set tIntervalTimer = CreateTimer()
call TimerStart(tIntervalTimer, StandardInterval, true, function ResourceDecayTick)
endmethod
endmodule
endlibrary
It lets me compile just fine with just this code in the map header.
But when I try to call the function in my code:
Code:
call SetUnitResource(udg_u_ResourceTempUnit,"Nova Sparks", 0, 100, false, 0, 0)
to add a resource called "Nova Sparks" to "udg_u_ResourceTempUnit" (unit variable in world editor) with minimum value 0 and maximum value 0 and no decay.
The error is: SetUnitResource is not defined, and after that I get tons of errors from the library (pretty much everything errors).
I have vJASS activated in the trigger editor.
I really have no clue what the problem is.
Can somebody help me?