requiring assistance to globally rot food

Hi!
I'm making a simulated version of medieval Europe as a school project
the player is a peasant who has to survive by working in the fields to get money to buy rations of bread
I'm trying to make a global rot script using "for each" in a turnscript
here's what I've got as a probably not working script:

foreach (, AllObjects()) {
  if (this.parent  <> object debug room) {
    if (HasAttribute(this, "freshness")) {
      this.freshness = this.freshness - 1
      if (this.freshness = 0) {
        if (ListContains(ScopeVisible(), this)) {
          msg (this + " has expired!")
          RemoveObject (this)
        }
        else {
          RemoveObject (this)
        }
      }
    }
  }
}

some help would be very much appreciated!


going to reply to my own post so people who THINK they cannot do what i said but wanna know the answer which they actually know will look at this and realise they can help :I


this means the object a script is being run on; in this case the turnscript.

When you make a foreach loop, you need to pick a name to represent the current item. Like this:

foreach (obj, AllObjects()) {
  if (obj.parent  <> object debug room) {
    if (HasAttribute(obj, "freshness")) {
      obj.freshness = obj.freshness - 1
      if (obj.freshness = 0) {
        if (ListContains(ScopeVisible(), obj)) {
          msg (GetDisplayName (obj) + " has expired!")
        }
        RemoveObject (obj)
      }
    }
  }
}

Hopre that helps :)


Log in to post a reply.

Support

Forums