Checking if a player is one of many locations

I'm not sure what the correct syntax for this code should be. I'm trying to check to see if a player is in a particular location, or more accurately, in one of many locations. I have all my tutorial locations inside a directory/room called Tut, which are separated into 4 additional child directories within Tut. The offending part of my current code is as follows:

tutLocations = GetAllChildObjects (Tut)
if (player.parent = tutLocations) {
  if (player.hitpoints <= 0) {
    player.hitpoints = 1
    msg ("That should have killed you...")
  }
}

Disclaimer: This is not the full code. I omitted the "else" portion of the code as I know that works. I know that the first line of code will create an objectlist containing all the children contained within Tut, but I'm not sure how to use that objectlist to check against player.parent. Any help or recommendations would be greatly appreciated. Do I need to be using a foreach loop to check all the objects in the list? I could keep messing around with it, but I figured I'd see if someone could tell me the "right" way to do it.


Make a new room. Put all your wanted rooms in that room. You can do that.
Putting things in boxes is a good way to clean up space, find things, or work with locations. I believe it will work for you.


The expression you want is:

if (ListContains (tutLocations, game.pov.parent)) {

This checks if a list contains a certain element.

(Note: referring to the player as game.pov rather than player is a good habit to get into. It means that if you later reuse the code in a game that allows the player to choose between different characters, it will still work)

However, there is a quicker and simpler way to do this that doesn't require a list. You can just do:

if (Contains (Tut, game.pov)) {

this tests if the player is somewhere inside the room/container Tut, including inside other objects that are inside it.


Awseome! Works perfectly. You are awesome! I knew it was going to be something simple that didn't require a bunch of mental calisthenics. I got hung up on the idea of needing a list, but it turns out I didn't need to create one in this case. Thanks again!


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

Support

Forums