Up to Main Index                           Up to Journal for October, 2020

                     JOURNAL FOR SUNDAY 4TH OCTOBER, 2020
______________________________________________________________________________

SUBJECT: Hello dolly, you’re giving me problems…
   DATE: Sun  4 Oct 20:20:14 BST 2020

I’ve spent the past week working on loading player and zone files that have
holding, wielding and wearing attributes. I’ve not looked at saving any of the
attributes yet as loading seemed to be the more complex half of the puzzle.
For now I’m just hand editing my player file to add the attributes. I then had
a sudden zap of inspiration and rewrote everything.

For the impatient, this is how it’s looking so far:


  Welcome back Diddymus!

    Main Menu
    ---------

    1. Enter game
    0. Quit

  Select an option:
  >1
  South bridge
  You are standing on the west side of an incomplete bridge. By the looks of
  it the city wants to expand onto the far banks of the river. Up river to the
  north you see another bridge in a similar state of construction.

  The only exit you can see from here is west.
  H:30>inv
  You currently have:
    a dagger - wielding
    a leather jerkin - wearing
    a small pottery jar
    a coin
    a floral belt - wearing
    a glass ball - holding
  H:30>w
  Street by south bridge
  You are at a junction in the street. To the east you see the south bridge
  over the city's river. North a path leads along the riverbank. West the
  street goes back into the city.

  You see a city guard here.

  You can see exits north, east and west.
  H:30>exam guard
  You examine the city guard.
  This is a tip top, smart city guard. Protector of the weak and justice to
  ill doers. They are wearing a leather cap and a leather jerkin. They are
  wielding a shortsword.
  H:30>


This shows me entering the game and using INV to look at my gear, which shows
I am wearing a belt and jerkin, holding a glass ball and wielding a dagger. I
then go west and examine a city guard who is wearing a jerkin and a cap while
wielding a shortsword.

Initially I made this work by polluting and abusing the Alias attribute. It
took quite a bit of effort to make it work. However, I wasn’t happy with the
end result, it felt like a dirty hack[1]. I tried to improve things by tidying
up the code, but my dirty hack was still a dirty hack.

I then had an illuminating think with myself:


  “What am I actually trying to do here?”
    “I’m trying to access the original reference a thing was unmarshaled with.”
  “Well the reference isn’t an alias. So where does it actually belong?”
    “Hrm, with the Thing…”
  “Bingo! So add a reference to Thing…”
    “Oh, okay, that will work…”
  “You’re welcome.”


I added a ref field to the Thing struct along with SetRef and Ref methods to
set and get the value through the has.Thing interface. All of the Alias hacks
fell away. Then I realised that I could just unmarshal the Ref directly into
the Thing and SetRef wasn’t even needed. I was also able to drop almost all of
the changes I’d made to the frontend/login.go and zones/zones.go sources.

What I am left with is minor tweaks to attr.thing, cmd.examine, zones.zones,
frontend.login and a new FindRef helper added the attr.Inventory type.

I think I’m going to have to rework the PostUnmarshal method to something more
generic that can also be used by Reset events for spawned items. I don’t want
to use Init or Reset as that could be confusing, maybe call it… Setup?

However, there are still a few other issues to sort out. While experimenting I
created a child’s toy doll wearing a tiny dress:


  %%
        Ref: O11
       Name: a small doll
    Aliases: DOLL
      Reset: AFTER→1m JITTER→1m SPAWN
    Cleanup: AFTER→10m JITTER→5m
   Location: L16
       Body: TINY_BODY
  Inventory: O12
    Wearing: O12

  This is a small child's toy doll.
  %%
       Ref: O12
      Name: a tiny dress
   Aliases: +DOLL:DRESS +TINY:DRESS
     Reset: AFTER→1m JITTER→1m SPAWN
   Cleanup: AFTER→10m JITTER→5m
  Wearable: TINY_BODY

  This is a tiny dress.
  %%


I can edit this into my inventory and have things work as expected:


  H:30>exam doll
  You examine the small doll.
  This is a small child's toy doll. They are wearing a tiny dress.
  H:30>


If I then ‘TAKE DRESS DOLL’ things break down as the doll’s body slots are not
synchronised — the doll still thinks it’s wearing the dress. Things become
even weirder if I try to junk the doll with or without the dress. Resets are
also a bit problematic as the doll won’t reset wearing the dress — or wearing
the correct dress as it still thinks it has the original dress on.

With the doll example I spotted an issue I hadn’t considered with respawning.
The dress should not respawn if taken from the doll. As it stands taking the
dress off of the doll will cause a new dress to respawn a while later. If the
dress does not have SPAWN specified then the dress becomes unique and we will
only get one dress no matter how many dolls spawn. Also, when the doll and
dress respawn the dress should be worn, it isn’t — this is there the Setup
method, or whatever I call it, comes in.

Just thought of another issue, players shouldn’t be able to use the PUT and
TAKE commands on other players and mobiles. Question is: how do you tell the
difference between a mobile and the doll, which is not a mobile. At the moment
a mobile is any non-player with a body specified.

Adding the doll has highlighted a lot of issues. I could just forget about the
doll. However, it raises problems that I am sure authors and players will run
into. Maybe not with a doll and a dress, but in general with an item that
holds, wears or wields another item.

For now I’ve not pushed anything out to the public dev branch as I’ve broken
more things than I’ve fixed :(

--
Diddymus

  [1] At work I’ve berated clients many times for abusing their systems and
      stuffing the wrong data into various database fields. Prime example,
      setting a first-name to “Robert (but he prefers to be called Bob)”.

      Imagine a mailshot, “Dear Robert (but he prefers to be called Bob)…”.
      All the client needs to do is ask for a nickname field to be added to
      the database *sigh*


  Up to Main Index                           Up to Journal for October, 2020