On object templates, but wouldn’t an instantiated object in a dobjFor(Take) be a different case? Would moveInto overlook this?
Doesn’t really make sense in the terms of class to programming. A class is supposed to be a template, hard-coding vocabWords breaks this construct. You might want a ‘sauce pan’ ‘pie pan’ ‘frying pan’ ‘dish pan’ maybe even a ‘pizza pan’.
I’m still getting an unusable pan. I’m trying to get my head around when to use variables in my class construct, and when not to. I understand to add custom variables in the class, but not sure when to add name, and vocabWords. I thought they would be assigned when the object is instantiated.
class Pan : Container
name = 'pan'
vocabWords = 'pan'
weight = 0
bulk = 0
bulkCapacity = 0
weightCapacity = 30
;
greysPans : Thing
name = 'frying pans'
vocabWords = 'castiron iron frying pan*pans'
location = greysKitchen
isPlural = true
oneTaken = nil
desc = "Cast iron frying pans, with wooden handles. They're in pretty good shape, but
some bare the marks of daily use. A couple are filled with scratches, and dings,
but they're hardly noticeable without close inspection."
disambigName = 'hanging pans'
dobjFor(Take)
{
action()
{
if(!oneTaken)
{
local hasPan = nil;
foreach(obj in gActor.contents)
{
if(obj.name == 'frying pan')
{
hasPan = true;
}
}
if(!hasPan)
{
//BUG : Taking the pan puts an un-usable fying pan in inventory.
fryingPan = new Pan;
fryingPan.name = 'frying pan';
fryingPan.initializeVocabWith('prized frying pan');
fryingPan.disambigName = 'prized pan';
fryingPan.desc = '<<me.name>> knows this as Greys prized frying pan. It\'s formed
of solid cast iron, and has a dark stained handle. Grey often remarked
in its ability to cook perfect meals, without needing much attention.';
fryingPan.location = greysKitchen;
fryingPan.bulkCapacity = 10;
fryingPan.weightCapacity = 30;
fryingPan.bulk = 8;
fryingPan.weight = 8;
if(fryingPan.bulk + gActor.getBulkHeld() < gActor.bulkCapacity &&
fryingPan.weight + gActor.getWeightHeld() < gActor.weightCapacity)
{
fryingPan.moveInto(gActor);
if(gActor == me)
{
"<<me.name>> takes one of Grey's prized frying pans.";
}else{
"{You/he} takes one of Grey's prized frying pans.";
}
}else{
fryingPan.moveInto(nil);
if(gActor == me)
{
"<<me.name>> has too many possessions.";
}else{
"{You/he} has too many possessions.";
}
}
}else{
if(gActor == me)
{
"<<me.name>> already has a frying pan.";
}else{
"{You/he} already has a frying pan.";
}
}
}else{
"You've already taken on of Grey's frying pans.";
}
// end action
}
// end dobjFor(Take)
}
;
This is ridiculous, because I already created a far more advanced armour class, and it instantiates just fine. The only difference is I used a slightly different method of setting the class variables. I made setter functions.
Armour
class Armour: Wearable
name = ''
type = 'armour'
wearLocation = ''
craftsmanship = ''
tn = 0
ar = 0
stats = ['combat', 'magic', 'vitality', 'perception', 'strength', 'dexterity', 'wisdom', 'charisma']
statMods = [0, 0, 0, 0, 0, 0, 0, 0]
skills = ['fire', 'break', 'track', 'hide', 'spot', 'diplomacy', 'intimidate', 'bluff',
'lockpick', 'pickpocket', 'decipher', 'detect traps', 'lore']
skillMods = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
ResElems = ['holy', 'fire', 'water', 'lightning', 'earth', 'air', 'dark']
res = [0, 0, 0, 0, 0, 0, 0]
construct(nameSet, vocabWordsSet, wearLocationSet, isPluralSet = nil)
{
name = nameSet;
vocabWords = vocabWordsSet;
wearLocation = wearLocationSet;
isPlural = isPluralSet;
initializeVocabWith(vocabWords);
}
set_location(locationSet)
{
location = locationSet;
}
set_craftsmanship(craftSet)
{
craftsmanship = craftSet;
}
// set the item description
set_desc(descSet)
{
desc = descSet;
}
// set the item owner
set_owner(actor)
{
owner = actor;
}
// set wornBy
set_wornby(actor)
{
wornBy = actor;
}
//set tn
set_tn(tnSet)
{
tn = tnSet;
}
// set Armour Rating
set_ar(arSet)
{
ar = arSet;
}
puton(surface, obj)
{
surface.tryMovingObjInto(obj);
}
// set a resistance value for piece of armour
set_resistance(element, percent)
{
switch(element)
{
case 'holy':
self.res[1] = percent;
break;
case 'fire':
self.res[2] = percent;
break;
case 'water':
self.res[3] = percent;
break;
case 'lightning':
self.res[4] = percent;
break;
case 'earth':
self.res[5] = percent;
break;
case 'air':
self.res[6] = percent;
break;
case 'dark':
self.res[7] = percent;
break;
}
}
// add skill
// add arrays
set_skill(skill, mod)
{
switch(skill)
{
case 'fire':
self.skillMods[1] = mod;
break;
case 'break':
self.skillMods[2] = mod;
break;
case 'track':
self.skillMods[3] = mod;
break;
case 'hide':
self.skillMods[4] = mod;
break;
case 'spot':
self.skillMods[5] = mod;
break;
case 'diplomacy':
self.skillMods[6] = mod;
break;
case 'intimidate':
self.skillMods[7] = mod;
break;
case 'bluff':
self.skillMods[8] = mod;
break;
case 'lockpick':
self.skillMods[9] = mod;
break;
case 'pickpocket':
self.skillMods[10] = mod;
break;
case 'decipher':
self.skillMods[11] = mod;
break;
case 'detect traps':
self.skillMods[12] = mod;
break;
case 'lore':
self.skillMods[13] = mod;
break;
}
}
// add stat bonus
// add arrays
set_stat(stat, mod)
{
switch(stat)
{
case 'combat':
self.statMods[1] = mod;
break;
case 'magic':
self.statMods[2] = mod;
break;
case 'vitality':
self.statMods[3] = mod;
break;
case 'perception':
self.statMods[4] = mod;
break;
case 'strength':
self.statMods[5] = mod;
break;
case 'dexterity':
self.statMods[6] = mod;
break;
case 'wisdom':
self.statMods[7] = mod;
break;
case 'charisma':
self.statMods[8] = mod;
break;
}
}
// handle wearing the item
dobjFor(Remove)
{
verify()
{
if(wornBy != gActor.getIdentityObject())
if(gActor == me)
illogicalAlready('<<me.name>> is not wearing {the dobj/him}.');
else
illogicalAlready('<<gActor.aName()>> is not wearing {the dobj/him}.');
}
action()
{
if(gActor == me)
{
"<<me.name>> removes {the dobj/him}.";
}else{
"<<gActor.aName()>> removes {the dobj/him}.";
}
me.tn -= gDobj.tn;
me.ar -= gDobj.ar;
gDobj.moveInto(gActor);
gActor.addToContents(gDobj);
gDobj.wornBy = nil;
}
}
// handle removing the items
dobjFor(Wear)
{
verify()
{
if(wornBy == gActor.getIdentityObject())
if(gActor == me)
illogicalAlready('<<me.name>> is already wearing {a dobj/him}.');
else
illogicalAlready('<<gActor.aName()>> is already wearing {a dobj/him}.');
}
action()
{
gDobj.wornBy = gActor;
me.tn += gDobj.tn;
me.ar += gDobj.ar;
if(gActor == me)
{
"<<me.name>> puts on the {the dobj/him}.";
// end wear by player
}else{
"<<gActor.aName()>> puts on the {the dobj/him}.";
// end wear by npc or monster
}
// End Wear action
}
}
;
shaggyGrassShorts = new Armour('shaggy grass shorts', 'shaggy grass shorts', 'legs', true);
shaggyGrassShorts.set_desc('Shaggy strands of grass encircle the waist, and
hang to about mid-thigh. \n <em>AR: 1</em>');
shaggyGrassShorts.set_location(startRoom);
shaggyGrassShorts.moveInto(me);
shaggyGrassShorts.set_wornby(me);
shaggyGrassShorts.set_tn(1);
shaggyGrassShorts.set_ar(1);