Requesting help with getting the object's parent

The basic gist is that when the player's stamina reaches 0, I want Quest to run a specific script that's dependent on which room the player is currently in. Obviously, the scripts will have the same name across all rooms, and all Quest would have to do is get the player's parent, and then run that object's specified script attribute.
Sort of a foreach (object, GetAllChildrenObjects (player.parent)), Do (object, "script") kind of deal, but getting the player's parent, rather than getting the player's children.

I just can't figure out how to get Quest to get the player's parent in such a way that it can then set that parent to an open-ended object function, and run the object's script. Everything else before and after that part I've got, just not this one part. The best solution I've found is to tie it all to roomenter/exit, which works fine, except the player can deplete their stamina in the room, and suffer no consequences until they leave. Which isn't that big of a deal, I suppose, but I would really prefer to set this whole mess to the player's stamina change script so that the script runs immediately upon the conditions being met, rather than when the player leaves or enters a room. And I really don't want the change script to be a mile-long list of if/if else where the game tediously checks to see if the player.parent = "room", when something open-ended would free me up to just add rooms as needed, without having to go back and edit the change script each time.
I've pored over the forums already, and I can't seem to find a solution.

Any help with this would be greatly appreciated.


you already have used the answer to your own question in your post, hehe.

NAME_OF_OBJECT_OR_NAME_OF_OBJECT_VARIABLE.parent


I don't quite understand what you want (I'm not clear on exactly what you want to do), but here's an example of something... hopefully it helps for whatever it is that you want to do.

<object name="room_1">
  <inherit name="example_type" />
</object>

<object name="room_2">
  <inherit name="example_type" />
</object>

<object name="book_1">
  <inherit name="book_type" />
  <attr name="parent" type="object">room_1</attr>
</object>

<object name="book_2">
  <inherit name="book_type" />
  <attr name="parent" type="object">room_1</attr>
</object>

<object name="book_3">
  <inherit name="book_type" />
  <attr name="parent" type="object">room_2</attr>
</object>

<object name="book_4">
  <inherit name="book_type" />
  <attr name="parent" type="object">room_2</attr>
</object>

<type name="book_type">
</type>

<type name="example_type">
  <attr name="example_script" type="script">
    msg ("example scripting")
  </attr>
</type>

<object name="player">
  <attr name="parent" type="object">room_1</attr>
  <attr name="stamina" type="int">100</attr>
  <attr name="changedstamina" type="script">
    if (this.stamina < 1) {
      foreach (object_variable, GetDirectChildren(player.parent)) {
        if (DoesInherit (object_variable, "book_type")) {
          do (object_variable.parent, "example_script")
        }
      }
    }
  </attr>
</object>

Really? Because I've tried

if (player.stamina <= 0) {
  do (player.parent, "script")
}

and got no results.


edited my previous post jsut now (sorry about that), so refresh and take a look at it.


hmm... you probably can't use the 'dot' notation in the 'do' Function....

you can do these to circumvent:

parent_variable = player.parent
if (player.stamina <= 0) {
  do (parent_variable, "script")
}

or (if the above doesn't work):

parent_variable = GetObject (player.parent)
if (player.stamina <= 0) {
  do (parent_variable, "script")
}

or if you want to do directly (I think you can can functions inside of function calls, but maybe you can't):

if (player.stamina <= 0) {
  do (GetObject (player.parent), "script")
}

p.s.

I'm assuming you named your universal scripts in your various rooms: script

this may be causing problems as the underlying code probably uses "script" too... you might want to re-name your script to something else, for example, see my first post, and my/its use of 'example_script' for its name, lol. You can name it whatever you want, but avoid any of the underlying code stuff, as you don't want to be over-writing it and wipe out its functionality.


Got it!
Apparently the problem wasn't with the scripting per se, but rather the ordering of my if chain. I had a series of messages that would print when stamina was between certain amounts (primarily to avoid giving the player an exact number for something abstract like stamina) and for whatever reason the script wouldn't run if it was at the end of the chain. I put it at the top, and it ran just fine.

Thank you for the assistance hegemonkhan. Didn't mean to waste your time. I knew the answer was probably something stupid and simple, and sure enough.


'order of operations (scripting)' is a hassle (it's not easy to understand, as it takes good logic and carefully seeing what is going on step by step with your scripts)... and quest doesn't have good controls over it... BEWARE complex looping with 'get input' or 'show menu / ShowMenu' ...


p.s.

if you post your code that wasn't working, we could take a look at it and (hopefully be able to) explain why it isn't working to you, if you're interested in knowing why.


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

Support

Forums