How To Count Items??

Hi,

Trying to make my own "Inventory" command. I call it "youve," for You Have.

    <pattern>youve</pattern>
    <script>
      foreach (item, ScopeInventory()) {
        msg ("You own " + GetDisplayName (item))
      }
    </script>
  </command>

And it works fine ... Unless Player has nothing in his inventory.

Tried to modify it so it would print a message if inventory is empty:

    <pattern>youve</pattern>
    <script>
      foreach (item, ScopeInventory()) {
        msg ("You own " + GetDisplayName (item))
        if (item.count = 0) {
          msg ("You ain't got nothin.")
        }
      }
    </script>
  </command>

Now, if Player has nothing in his inventory, Nothing happens. I mean, program doesn't print anything. Just displays the little box for him to enter next command.

However, if Player does have something in his inventory, it prints an error msg.

You own a TV
Error running script: Error compiling expression 'item.count = 0': CompareElement: Operation 'Equal' is not defined for types 'Object' and 'Int32'

What do I hafta do??


Another question while I'm at it. Trying to do in poor ol' Bob:

  <command>
    <pattern>attack #object#; kill #object#; strike #object#; hit #object#</pattern>
    <unresolved>Ain't none o' them nowheres.</unresolved>
    <script>
      Bob.live = Bob.live - 1
      if (Bob.live = 0) {
        msg ("Bob's dead.")
      }
      else if (Bob.live =  2) { <-------- This line.
        msg ("Bob still kickin'")
      }
      else if (Bob.live =  -1) {
        msg ("Bob's already as dead as he's gonna get.")
      }
    </script>
  </command>

Bob has an attribute "live" set to four when game begins. Code above works fine. But can I use an inexact number instead of live always equal a preset integer?? I change the indicated line to

      else if (Bob.live =  > 0) {
        msg ("Bob still kickin'")
      }

I get this long, indecipherable error message:

Error running script: Error compiling expression 'Bob.live = > 0': SyntaxError: Unexpected token ">"; expected one of "-"

Appreciate any insight.


Okay, so for each item in the inventory you print first the item's name, and then "You ain't got nothin." if the item has a count atttribute set to 0.

Some stacking systems have a count attribute which tells you how many items are in a stack. But I think you want that message to appear if the player has nothing; rather than if they own an empty stack of any particular item. So…

items = ScopeInventory()
foreach (item, items) {
  msg ("You own " + GetDisplayName (item))
}
if (ListCount (items) = 0) {
  msg ("You ain't got nothin.")
}

I assume the objective here is teaching yourself how the code works, or you're going to modify it later. Otherwise it might be simpler to use a function like FormatList or FormatObjectList (both of which have slightly different annoying limitations).
For example:

  list = FormatList (ScopeInventory(), "<br/>You own ", "<br/>You own ", "nothing")
  if (list = "nothing") {
    msg ("You ain't got nothin.")
  }
  else {
    msg ("You own " + list)
  }

or

list = FormatObjectList ("You own ", game.pov, "and", ".")
if (list = "") {
  msg ("You ain't got nothin.")
}
else {
  msg (list)
}

  else if (Bob.live =  > 0) {

Almost got it. You want:

  else if (Bob.live > 0) {

(you could use > for "greater than" or >= for "greater than or equal to", but in this case it doesn't make any difference because if it's zero the code wouldn't get here. Other comparisons are < (less than), <= (less than or equal to), and <> (not equal to). Note that >=, <= and <> are treated as words by the interpreter. They need to have the characters in the right order; which isn't true in some programming languages)

Also, in this script you should probably be using object (the object the player entered in the command) rather than Bob. Unless you want the player to kill Bob by typing "attack myself".

So you'd have:

if (not HasInt (object, "live")) {
  // if the object doesn't have a "live" attribute…
  msg ("That isn't something you can fight.")
}
else {
  object.live = object.live - 1
  if (object.live = 0) {
    msg (CapFirst (GetDisplayName (object)) + "'s dead.")
  }
  else if (object.live >= 0) {
    msg (GetDisplayAlias (object) + " still kickin'")
  }
  else {
    msg (GetDisplayAlias (object) + "'s already as dead as " + object.gender + "'s gonna get.")
  }
}

Thanks, Mr. Angel. I am plugging away, making some small progress.


I've gotten this error message a couple of times. Don't know what caused it, and I certainly have no idea what it means.

System.NullReferenceException: Object reference not set to an instance of an object.
   at TextAdventures.Quest.EditorControls.ScriptEditorControl.AddNewScriptCommand(String script)
   at TextAdventures.Quest.EditorControls.ScriptEditorControl.cmdAddScript_Click(Object sender, RoutedEventArgs e)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

That looks like a bug in the editor. Don't know if there's something specific in a game that causes it; but I've seen people before say that reinstalling Quest helps; or to try running the editor as an administrator.


OK, I uninstalled Quest. Made sure I deleted all the Registry entries. Downloaded Quest and installed it again. We'll hope for the best.


Quest seems to be working. We'll keep our fingers crossed. Now, why won't this code work:

      <inherit name="editor_object" />
      <alt type="stringlist">
        <value>table</value>
        <value>ct</value>
      </alt>
      <look type="script">
        if (ListContains(ScopeVisible(), pistol)) {
          msg ("A pistol is on the coffee table.")
        }
        else {
          msg ("There is nothing on the table.")
        }
      </look>
      <take />
      <drop type="boolean">false</drop>
      <not_all />
      <listchildren />

Wanted Player to see the pistol when he looked at coffee table. Made sure pistol was visible and coffee table "list children" was true. But I always get "There is nothing on the table."

Any idea??


I'm not sure; it's a long time since I looked at the weirdness of 'hide children'.

Does the pistol show up in the list of objects in the room if you just type "look"?
Does it work the second time if you look at the table twice?
Is the table a surface or an open container?

In any case, that code has issues. It should generate "The pistol is on the coffee table." if the player looks at the table when the pistol is visible. This includes if the player has already picked up the pistol.

I suspect that what you really want is:

        if (Contains (this, pistol)) {

which tests if the pistol is in/on the table


OK, I changed the line to your suggestion, Mr. Angel. Now "Examine table" gets "A pistol is on the coffee table." But when I try to take or examine it, I get, "I can't see that."

At this point, the answers to your questions:

Does the pistol show up in the list of objects in the room if you just type "look"? - No.
Does it work the second time if you look at the table twice? - No.
Is the table a surface or an open container? - I checked the box on Features page that says, "Container: Object is a container or surface, or can be opened and closed." Made no difference. I still get nothing but, "I can't see that."


I figured it out. When you make the object a container, another tab appears. Now you have the option to make it a surface. Then, the boxes to make children visible right away or only when Player looks at object (Coffee table) appear.


Been looking at the Text Processor page in the documentation: http://docs.textadventures.co.uk/quest/text_processor.html

I can get most of the commands to work. For example. in the description of Bob, I put "You see Bob. {if bob.life=2:Bob not looking well.}" And if Bob's life attribute is two, it prints "not looking well."

But I cannot get select to work.

{select:bob.life:Bob looking well:Bob sick:Bob dead:Bob gone.}

(A few minutes later.) OK, I get it. bob.life has to be zero to three. If it's four or minus one, select doesn't work. But wouldn't you think if bob.life was not in range, Quest would just ignore it. Instead it prints the select command itself. The Player sees: "You see Bob. {select:bob.life:Bob looking well:Bob sick:Bob dead:Bob gone.}"

So I'll just hafta to make sure the attribute never gets set too high or too low.


Been going through Quest Documentation. Learning. Learning slow, but learning.

Can't get "player.alias" to work.

<look>Cooter is slumped at the kitchen table. {once:"Hi  {player.alias}, " he says.}</look>

The first time player and Cooter encounter each other, I want Cooter to greet player. But the above line produces:
Cooter is slumped at the kitchen table. "Hi me, " he says.

Hi me instead of Hi Sam. Any idea??


player.alias is set to be the same as player.pov_alias at the start of the game. This basically ensures that when a command response references the player, it uses the right words. (for example, to make "kick self" respond "I can't kick myself" instead of "I can't see that" or "I can't kick him")

If you want the player's external alias, you want player.external_alias.

Basically, pov_alias is how you refer to yourself, external_alias is what everyone else calls you. alias is changed to be equal to one of those whenever the object starts or stops being controlled by the player. (objects that the player can't control just have a single alias)


Got it! Thanks.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums