Forum Discussion
NB_
8 years agoRoku Guru
I am most curious what that error means - and perhaps RokuKC will shed some light.
But in the mean time, Komag... don't you notice how this massive if-elseif-elseif-...ad-nauseam resembles a dictionary (roAA)?
Say initially you create a catalog in main() or such:
Then later when you need to find an object in some method (so m is not global), it's as simple as asking for
Now there are caveats to that - say these objects are not constants and you don't want when you create two different ones - cutlass1 and cutlass2 - and don't want when changing properties of cutlass1 (say change slot-equipped or make visible or make it dull) - don't want the same to happen to cutlass2? Then that means you need to create a copy from the WHOLE_EARTH_CATALOG samples/models/templates. If models are "flat" (i.e. single-depth of roAA), that's as easy as
And so you have it. If you want to kick it up a notch, for a multi-level "deep copy"? The look for a deepCopy function (there must have been a few here in the forum) - but absolutely the laziest way to make a deep copy - that will work in many cases - is to do
Bam!
But in the mean time, Komag... don't you notice how this massive if-elseif-elseif-...ad-nauseam resembles a dictionary (roAA)?
Say initially you create a catalog in main() or such:
m.WHOLE_EARTH_CATALOG = {
blocker: {
kind: "infoTh"
'kind: "block" ' If we use this, then it would block flying Items, I think I don't want that
name: "blocker"
objNm: "blocker"
blocker: TRUE
'vis: FALSE
swap: TRUE
}
handL: {
sprite: ["sprite_handL", "sprite_handL_2", "sprite_handL_3"]
}
handR: {
sprite: ["sprite_handR", "sprite_handR_2", "sprite_handR_3"]
}
"short sword": {
kind: "005 sword"
name: "short sword"
objNm: "short sword"
code: 5
blocker: FALSE
sprite: ["sprite_sword1", "sprite_sword1_2", "sprite_sword1_3"]
spriteDraw: FALSE
inven: {
weight: 1
value: 5
equip: TRUE
slot: "ield" ' Match last 4 of "right wield" OR "left wield"
eqp1: "equip other"
equipped: FALSE
eqSlot: "" ' For exact slot name
cd: 8 ' Cooldown, in cycles
}
statsArr: [ ["att", 2] ]
dscr: getCreateItemDscr(5) ' "SHORT SWORD: A short sturdy blade of iron, simple and effective."
}
cutlass: {
objct = {
kind: "005 sword"
name: "cutlass"
objNm: "cutlass"
code: 6
blocker: FALSE
sprite: ["sprite_sword2", "sprite_sword2_2", "sprite_sword2_3"]
spriteDraw: FALSE
inven: {
weight: 1.2
value: 8
equip: TRUE
slot: "ield" ' Match last 4 of "right wield" OR "left wield"
eqp1: "equip other"
equipped: FALSE
eqSlot: "" ' For exact slot name
cd: 10 ' Cooldown, in cycles
}
statsArr: [ ["att", 3] ]
dscr: getCreateItemDscr(6) ' "CUTLASS: Nautical in design, with a slight curve like the bow of a ship, this blade will stab and slice as you see fit."
}
...
}
Then later when you need to find an object in some method (so m is not global), it's as simple as asking for
glbl = getGlobalAA()No chained if-s, works very fast.
' then do something with '
glbl.WHOLE_EARTH_CATALOG.cutlass
glbl.WHOLE_EARTH_CATALOG["short sword"]
Now there are caveats to that - say these objects are not constants and you don't want when you create two different ones - cutlass1 and cutlass2 - and don't want when changing properties of cutlass1 (say change slot-equipped or make visible or make it dull) - don't want the same to happen to cutlass2? Then that means you need to create a copy from the WHOLE_EARTH_CATALOG samples/models/templates. If models are "flat" (i.e. single-depth of roAA), that's as easy as
newCutlass = { }
newCutlass.append(glbl.WHOLE_EARTH_CATALOG.cutlass) ' shallow copy
And so you have it. If you want to kick it up a notch, for a multi-level "deep copy"? The look for a deepCopy function (there must have been a few here in the forum) - but absolutely the laziest way to make a deep copy - that will work in many cases - is to do
newCutlass = parseJSON(formatJSON(glbl.WHOLE_EARTH_CATALOG.cutlass))
Bam!