Hi there,
i have a function
now, i want to be able to simply put a created tile (an instance of Tile) into the function like this:
for now, i came up with this solution, looping through every instance and searching for the same name:
is there a better solution for this? it doenst have to be a string, i can be something similar that makes it as readable.
i have a function
JASS:
function AddTile takes integer x, integer y, Tile whichtile returns nothing
now, i want to be able to simply put a created tile (an instance of Tile) into the function like this:
JASS:
local Tile forest = Tile.create("Forest")
local Tile mountain = Tile.create("Mountain")
local Tile castle = Tile.create("Castle")
// ---------------------
set forest.evasion = 20
set forest.defense = 1
// ---------------------
set mountain.evasion = 30
set mountain.defense = 1
// ---------------------
set castle.evasion = 20
set castle.defense = 2
set castle.healing = 20
JASS:
call ch1.AddTile(0, 0, Tile["Forest"])
for now, i came up with this solution, looping through every instance and searching for the same name:
JASS:
library TileLib
struct Tile
static integer index = 0
static integer array tileid
static string array tilename
integer evasion
integer defense
integer healing
string name
static method operator [] takes string s returns thistype
local integer i = 0
loop
if tilename[i] == s then
return tileid[i]
endif
set i = i + 1
exitwhen i == index
endloop
return 0
endmethod
static method create takes string s returns thistype
local thistype this = thistype.allocate()
set tileid[index] = this
set tilename[index] = s
set index = index + 1
return this
endmethod
method destroy takes nothing returns nothing
call this.deallocate()
endmethod
endstruct
endlibrary
is there a better solution for this? it doenst have to be a string, i can be something similar that makes it as readable.