Hi
I'm working on a system to create spells easy via code because I want to be able to recall some of the parameters.
This is the code:
I'm using an ID-Generator for the spells
I attached the picture of what gets compiled.
Now, it seems like there is a problem with the new id of the created spell.
I might have compiled once, when i confused "NewSpellId" and "OldSpellId" in a spell creation function. Might the problem result from this? And how do I fix this?
I imported the objEditingOutput into another map and i got the same problem.
EDIT: found the mistake, I used the wrong variable in the spellDefinition
I'm working on a system to create spells easy via code because I want to be able to recall some of the parameters.
This is the code:
JavaScript:
public constant Table SPELL_TABLE = new Table()
constant ID_GEN = new IdGenerator('A000')
public LinkedList<SpellDef> Spells = new LinkedList<SpellDef>
int counter = -1
function count() returns int
counter++
return counter
public class SpellDef
string n = "."
int id
int spellId
Targettype ttype
boolean channel = false
real range
real radius
string icon = "."
string tt = "."
int mana = 0
function generate(SpellDef sd)
ChannelAbilityPreset sp = new ChannelAbilityPreset(sd.id, 1, not sd.channel)
sp.setName(sd.n)
sp.presetTargetTypes(sd.ttype)
sp.presetIcon(sd.icon)
sp.setTooltipNormal(1,sd.n)
sp.setAreaofEffect(1, sd.radius)
sp.setCastRange(1, sd.range)
sp.setTooltipNormalExtended(1,sd.tt)
sp.setManaCost(1,sd.mana)
@compiletime function spellCode()
SpellDef sd = new SpellDef
sd.n = "Firebolt"
sd.id = count()
sd.spellId = ID_GEN.next()
sd.ttype = Targettype.UTARGET
sd.range = 500
sd.radius = 0
sd.icon = "BTNFlare.blp"
sd.tt = "Classic"
sd.mana = 50
createSpell(sd,compiletime)
sd.n = "Frostbolt"
sd.id = count()
sd.spellId = ID_GEN.next()
sd.ttype = Targettype.UTARGET
sd.range = 500
sd.radius = 0
sd.icon = "BTNCloudOfFog.blp"
sd.tt = "Classic"
sd.mana = 50
createSpell(sd,compiletime)
function createSpell(SpellDef sd, boolean c)
if c
generate(sd)
else
Spells.add(sd)
SPELL_TABLE.saveInt(sd.spellId, sd.id)
init
spellCode()
Code:
public constant UNIT_ID_GEN = new IdGenerator('s000')
public constant HERO_ID_GEN = new IdGenerator('K000')
public constant ABIL_ID_GEN = new IdGenerator('A000')
public constant BUFF_ID_GEN = new IdGenerator('F000')
public constant ITEM_ID_GEN = new IdGenerator('O000')
public class IdGenerator
private int i1
private int i2
private int i3
private int i4
construct(int start)
i1 = start mod 256
i2 = (start mod 65536) div 256
i3 = (start mod 16777216) div 65536
i4 = start div 16777216
function next() returns int
if i1 < '~'
i1++
if(i1 == '_')
i1++
else if i2 < '~'
i1 = '!'
i2++
if(i2 == '_')
i2++
else if i3 < '~'
i1 = '!'
i2 = '!'
i3++
if(i3 == '_')
i3++
else if i4 < '~'
i1 = '!'
i2 = '!'
i3 = '!'
i4++
if(i4 == '_')
i4++
else
error("No vaild id left")
return 0
return i1 + (i2 * 256) + (i3 * 65536) + (i4 * 16777216)
I attached the picture of what gets compiled.
Now, it seems like there is a problem with the new id of the created spell.
I might have compiled once, when i confused "NewSpellId" and "OldSpellId" in a spell creation function. Might the problem result from this? And how do I fix this?
I imported the objEditingOutput into another map and i got the same problem.
EDIT: found the mistake, I used the wrong variable in the spellDefinition
Attachments
Last edited: