Announcing the presence of a "patrolling" character?

benn
Hi. I have a quick dumb question involving a character that moves on their own. This might be an easy fix but I'm not getting the result I'm looking for.

So I've set up a turn script that's working well enough: every 3 turns, the character moves to the next room, cycling through a loop of 8 ultimately. And I have a message pop up as this character exits a room, leaving the player. But nothing kind of announcing the character's arrival or presence initially. Whether they enter a room I'm in, or vice versa, they're only just ever listed in the "places & objects" tab.

Ideally, I'd like a 'first time' sort of script, where I first provide a sort of more detailed intro/description, but then have it just say 'hey, this character's there too' after that. I tried setting up something like that through the same script I had moving them, but that made it so I got their intro every time the player ran into them in each room. I'd also like to have it set that same way so if they're already in a room the player's entering (not based on the patrolling character making the move essentially). Is there an easy way to have that description pop up once across the board, the first instance they & the player share the same room, no matter which room that happens to be? I feel like I'm missing something kind of obvious. Thanks in advance!

XanMag
I have no clue if this will be helpful or not. This is one of the situations I started working on in my tutorial game and got it working but that was months ago. It's one of the last rooms I have yet to describe fully, so...

I'll just drop this here and you can take a look. I hope it is helpful.

  <object name="patrolling guard room 1">
<inherit name="editor_room" />
<enter type="script">
</enter>
<firstenter type="script">
msg ("An alarm sounds when you enter the room. A guard will be here shortly. Better get a move on!")
SetObjectFlagOn (Magoo, "patrolled")
guarding
</firstenter>
<exit alias="southeast" to="patrolling guard room 2">
<inherit name="southeastdirection" />
</exit>
<exit alias="southwest" to="patrolling guard room 3">
<inherit name="southwestdirection" />
</exit>
<command name="explain guards cmd">
<pattern>explain; explain the room; explain room</pattern>
<script><![CDATA[
msg ("I'll let this stand alone. Hopefully you can make sense of it from exploring the GUI.<br/><br/>I have used a combination of flags set on the guards and Turn Script which moves the guards to the connected rooms.<br/><br/>Just be sure to look at the flags and the 'guarding TS' in the tree of things to the left of the GUI.<br/><br/>Please ask if you have any questions.")
]]></script>
</command>
<object name="Magoo">
<inherit name="editor_object" />
<inherit name="editor_player" />
<inherit name="namedmale" />
<attr name="pov_look">You're Magoo. A simple being trapped in a test game.</attr>
<look type="script">
if (game.pov = Xanadu) {
msg ("Holy moly! That looks exactly like you! To take control of Magoo, just type 'switch to Magoo'.")
}
else {
msg ("You are a simple being trapped in a test game.")
}
</look>
</object>
</object>
<object name="patrolling guard room 2">
<inherit name="editor_room" />
<exit alias="northwest" to="patrolling guard room 1">
<inherit name="northwestdirection" />
</exit>
<exit alias="west" to="patrolling guard room 3">
<inherit name="westdirection" />
</exit>
<command name="explain guards cmd1">
<pattern>explain; explain the room; explain room</pattern>
<script><![CDATA[
msg ("I'll let this stand alone. Hopefully you can make sense of it from exploring the GUI.<br/><br/>I have used a combination of flags set on the guards and Turn Script which moves the guards to the connected rooms.<br/><br/>Just be sure to look at the flags and the 'guarding TS' in the tree of things to the left of the GUI.<br/><br/>Please ask if you have any questions.")
]]></script>
</command>
</object>
<object name="patrolling guard room 3">
<inherit name="editor_room" />
<exit alias="east" to="patrolling guard room 2">
<inherit name="eastdirection" />
</exit>
<exit alias="northeast" to="patrolling guard room 1">
<inherit name="northeastdirection" />
</exit>
<command name="explain guards cmd2">
<pattern>explain; explain the room; explain room</pattern>
<script><![CDATA[
msg ("I'll let this stand alone. Hopefully you can make sense of it from exploring the GUI.<br/><br/>I have used a combination of flags set on the guards and Turn Script which moves the guards to the connected rooms.<br/><br/>Just be sure to look at the flags and the 'guarding TS' in the tree of things to the left of the GUI.<br/><br/>Please ask if you have any questions.")
]]></script>
</command>
</object>
<turnscript name="guarding TS">
<enabled />
<script>
if (ListContains(ScopeVisible(), guard)) {
msg ("You and the guard have happened to stumble into the same room. He looks incensed that he has been put to work. He takes his frustration out on you with his billy club. He pummels you to death. Sorry.")
finish
}
if (GetBoolean(Magoo, "patrolled")) {
if (GetBoolean(guard, "room1")) {
if (game.pov.parent = patrolling guard room 2) {
msg ("You look over your shoulder to the northwest and into patrol room 1 and you see the guard patrolling that room.")
}
else if (game.pov.parent = patrolling guard room 3) {
msg ("You look over your shoulder to the northeast and into patrol room 1 and you see the guard patrolling that room.")
}
}
else if (GetBoolean(guard, "room2")) {
if (game.pov.parent = patrolling guard room 1) {
msg ("You look off to your southeast and see a nasty looking guard patrolling guard room 2.")
}
else if (game.pov.parent = patrolling guard room 3) {
msg ("You hear some noise to the east and you take a look that way. You see the guard loitering in room 2.")
}
}
else if (GetBoolean(guard, "room3")) {
if (game.pov.parent = patrolling guard room 2) {
msg ("The guard is certainly making some noise off to the west as he searches patrol room 3 for you.")
}
else if (game.pov.parent = patrolling guard room 1) {
msg ("As you dawdle in room 1, the guard is frantically searching for you in patrol room 3 to your southwest.")
}
}
}
</script>
</turnscript>
<command name="look guard cmd">
<pattern>look at guard; x guard</pattern>
<script>
if (GetBoolean(guard, "room1")) {
msg ("You look carefully into room 1 where you believe the guard to be... He is large and angry. He is wielding a fearsome looking billy club.")
}
else if (GetBoolean(guard, "room2")) {
msg ("You look carefully into room 2 where you believe the guard to be... He is large and angry. He is wielding a nasty and heavy billy club.")
}
else if (GetBoolean(guard, "room3")) {
msg ("You look carefully into room 3 where you believe the guard to be... He is large and angry. He is weilding a fearsome looking billy club.")
}
</script>


And here is the 'guarding' function.

SetTurnTimeout (1) {
MoveObject (guard, patrolling guard room 1)
SetObjectFlagOn (guard, "room1")
SetObjectFlagOff (guard, "room3")
SetTurnTimeout (2) {
MoveObject (guard, patrolling guard room 2)
SetObjectFlagOn (guard, "room2")
SetObjectFlagOff (guard, "room1")
SetTurnTimeout (2) {
MoveObject (guard, patrolling guard room 3)
SetObjectFlagOn (guard, "room3")
SetObjectFlagOff (guard, "room2")
SetTurnTimeout (2) {
MoveObject (guard, patrolling guard room 1)
guarding
}
}
}
}


If you want me to hack an explanation out of that, I would be glad to do it, but not tonight! It's late. I've had a few drinks. GO BRONCOS!

In the meantime, if you want a closer look, I just posted to the game announcements section of the forum, the .aslx file for the entire tutorial to date. You can download that and take a look in the GUI at all the code mess above if that makes it easier.

And good luck!

HegemonKhan
the 'parent' Object Attribute of an Object, is very useful:

http://docs.textadventures.co.uk/quest/ ... arent.html (the 'parent' Object Attribute of Objects)
^^^^^^^^^^
http://docs.textadventures.co.uk/quest/ ... bject.html
^^^^^^^^^^
http://docs.textadventures.co.uk/quest/elements/
^^^^^^^^^^
http://docs.textadventures.co.uk/quest/
^^^^^^^^^^
path to find/get to the 'parent' link in the online doc site

---------------------------------

<object name="room">
<object name="player">
</object>
</object>


is the same as:

<object name="room">
</object>

<object name="player">
<attr name="parent" type="object">room</attr>
</object>


is the same as:

player.parent = room

is the same as:

MoveObject (player, room)

is (nearly) the same as:

http://docs.textadventures.co.uk/quest/ ... tains.html

// this, of course, requires that the 'player' Object is indeed inside (a child of) the 'room' Object (the parent):

if (Contains (room, player)) {
// script(s)
}


-------------------------------------

sample example 1 (using 'parent' Object Attribute):

<turnscript name="global_turnscript">
<enabled />
<script>
if (player.parent = npc1.parent) {
firsttime {
// your first-time script(s)
} otherwise {
// your non-first-time script(s)
}
}
</script>
</turnscript>


sample example 2 (using 'Contains' Function + 'parent' Object Attribute):

(though, why use 'Contains' + 'parent', when you can just use 'parent', which should be, or at least seems to be, more efficient)

<turnscript name="global_turnscript">
<enabled />
<script>
if (Contains (player.parent, npc1)) {
firsttime {
// your first-time script(s)
} otherwise {
// your non-first-time script(s)
}
}
</script>
</turnscript>


OR

<turnscript name="global_turnscript">
<enabled />
<script>
if (Contains (npc1.parent, player)) {
firsttime {
// your first-time script(s)
} otherwise {
// your non-first-time script(s)
}
}
</script>
</turnscript>

Pertex
go to codeview and add a changedparent script to your npc. In my example it's an orc

    
<object name="orc">
<inherit name="editor_object" />
<changedparent type="script">
if(this.parent=player.parent){
msg("orc is coming")
}
</changedparent>
</object>

benn
Thanks guys!

Xan- I appreciate that & saw your other forum reply about setting up a patrolling character. It was instrumental in helping me to get the character to move. Originally, I was thinking about using flags to set up the intro description vs the repeating message, but figured a 'first time' would work just as well. Situationally, what I've got going is more of a random occurrence thing. The 'rooms' are sort of a big outdoor area & if the character & the player don't line up, the player doesn't necessarily need to know which other room the character's in.

HK- Thanks! I tried your method but ran into two minor problems. First, I noticed that if the Player & Character both arrive in a room at the same time, the description doesn't seem to happen until that subsequent turn. Secondly, since the loop is on a 'three turn > move' interval, I get that first description, but then I get the follow up the next turn & every turn the character & player share a room. Ideally, I'd just like the that script with the messages to run once announcing their presence on that very first turn they end up sharing a room, & only have it subsequently the next first turn it happens lines up like that.

pertex- Thanks! That code helped to make sure I get that message that very first turn, but then the subsequent message doesn't seem to appear after that. (But maybe I need to mess with it more. I just got your reply as I was already replying & just tried to apply it once here) EDIT: Sorry, I messed with it more & while it's a little wonky if the player enters after the character, it works very well in the character enters after the player. Anyway to make the reverse happen too? is that something I have to apply as a changedparent script on the player?

HegemonKhan
ya, that might work for you, setting up the special 'changed' script on both your player and npc Objects:

<object name="player">
<attr name="changedparent" type="script">
if (player.parent = npc.parent) {
firsttime {
// script(s)
} otherwise {
// script(s)
}
}
</attr>
</object>

<object name="npc">
<attr name="changedparent" type="script">
if (player.parent = npc.parent) {
firsttime {
// script(s)
} otherwise {
// script(s)
}
}
</attr>
</object>


-------------------------

using a Turnscript should work too... but you got to set it's scripts and all your other (non-Turnscript) scripts up right... in order to get the desired sequence/order of scripts occuring as you want them to do so.

--------------------------

the special 'changed' Script is nearly identical to the Turnscript, they both fire/run/check every (well, depending on how it is set up with/for the Turnscript, anyways) internal turn.

EDIT: actually, maybe the special 'changed' script doesn't work with the internal turn... as it seems to activate immediately upon the chosen attribute's value, changing. I think it was Jay (Jaynebonne) who explained how the 'changed' Script and Turnscript worked, but as can be seen, it's been awhile and I've forgotten what he said about them. Pertex also probably knows how both work and can explain it, too. Pixie probably also. They're the main moderators who post on the forum, who're all really good coders and who know quest very well.

if you don't understand the special 'changed' script, this is how it works:

on every internal turn (this is basically any click or command/input box text entry that you do while playing the game) if the attribute's value, via putting the attribute in: <attr name="changedATTRIBUTENAME" type="script">, changes, then run/activate/execute the added scripts.

Turnscript (if set up right): on every internal turn, run and/or check whether to run (depends upon the scripts) every script added to it.

benn
Yeah, having the kind of hierarchy I set up with the turn script, I think it was basically running the move every turn, despite the character already being in the room. So basically it kept having the character enter over & over.

Applying the changedparent script like pertex's example to the character works for when the character enters after the player. And it seems like adding an inverted version onto the player works for when the player enters after the character. Thank you very much for the assist, guys! Now suddenly, I did notice that if the player leaves, the character's "leaving" message now seems to appear, but I'm not too bothered by that.

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

Support

Forums