Followers

Garan
I am trying to implement a simple combat system for my adventure. I already have the details, that is not what this is about.
However, I am trying to have a way to get "people" in the world to follow you from room to room.
My idea that I am trying to get work is as follows:
I have a list of "followers". This list will be checked each time the player moves into a new room, and moves each object in the list.
Unfortunately, I cannot find something that will be checked each time the player moves into a room, short of adding a script to the "entering a room" part. I also don't know how to go through the list with a for loop.
Any thoughts, suggestions, etc would be appreciated.

MerchantToo
For moving through your list and moving the followers use something like this:

foreach (NPC, ListOfFollowers)
NPC.parent = player.parent


As for getting it to run every time the player moves, I would probably make the above into a function called UpdateRoomContents, and then make an inherited type with the attribute `enter' set to call the function. Then add this type to all rooms. Maybe there's something easier to do with a timing script, but I haven't looked into them at all yet because I'm new here. Hope I make sense..

Garan
Hmm...
I like the idea, but I still have the whole "in list" problem, as you can't use "foreach" for items in a list (at least not to my knowledge).

Pertex
The wiki is your friend
Using lists: http://quest5.net/wiki/Using_Lists
The other thing can be done with a turnscript: http://quest5.net/wiki/Using_timers_and_turn_scripts

sgreig
Garan> foreach iterates through each item in the list you specify, and stores the value of the current item in the iterator variable.

Garan
Ok, so I have tried Foreach. However, I get the following error message: Error running script: Unknown object or variable 'Followers'
Is this a problem with the syntax I am using, or am I calling the list the wrong way?
Here is how I am calling it:
  <function name="NPCMove">
foreach (NPC, Followers) {
NPC.parent = player.parent
}
</function>

Alex
There's no variable or parameter named "Followers" in that function.

Garan
So I would have to add "Followers" to the parameters of the function? Makes sense. Thank you.
EDIT: Never mind, I still have an issue. Now it is saying: Error running script: Error compiling expression 'Followers': Unknown object or variable 'Followers'
I know that I already have the list defined before that point.

sgreig
If you're using the regular editor, you have to make sure you specify "Followers" as a parameter when you call that function. But, you also have to make sure you set "Folowers" as an accepted parameter in the function as well. I've made that mistake a couple of times.

Garan
I have made sure that the parameters are set by both the function and calling it.

MerchantToo
So then the code should look like this:

  <function name="NPCmove" parameters="Followers">
foreach (NPC, Followers) {
NPC.parent = player.parent
}
</function>


and the call should be:

NPCmove(ListOfFollowers)


or if you make your list of followers at the game level then:

NPCmove(game.ListOfFollowers)


Where do yo create your list? Maybe you should also check your capitalisation because Followers and followers are different variables.

Pertex
If this doesn't help, it would be the best to post your gamefile here. Then we could have a look at it

Garan
Ok, here is the code. I only have two rooms, as this is essentially my priority right now. As you can see I have "Followers" defined, and that when you ask Delvas about joining, it asks you whether you want him to join you. If you say yes, then it should add him to "Followers", but the same error comes up.
<!--Saved by Quest 5.1.4426.19610-->
<asl version="510">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Aurinath">
<gameid>7e4d54c0-f950-46a4-abb5-5412c987f86d</gameid>
<version>1.0</version>
<description>An RPG that focuses on the decisions that are made during the course of the game- almost every decision will change the game in some way.</description>
<author>Avram Levitt</author>
<category>RPG</category>
<start type="script">
Followers = NewObjectList()
if (player.parent = The Clearing) {
}
</start>
</game>
<object name="The Clearing">
<inherit name="editor_room" />
<description>A clearing in a meduimly dense forest.</description>
<alias>small clearing</alias>
<usedefaultprefix type="boolean">false</usedefaultprefix>
<prefix>a</prefix>
<enter type="script">
NPCMove (Followers)
</enter>
<exit alias="west" to="The western path">
<inherit name="westdirection" />
</exit>
<object name="Large stick">
<inherit name="editor_object" />
<take />
<takemsg>You pick up the large stick and put in your pack.</takemsg>
<dropmsg>You drop the stick. </dropmsg>
<look>It is a large stick with no defining features. It seems to be a pointless waste of inventory space.</look>
<alias>a large stick</alias>
<inventoryverbs>Look at; Use; Drop</inventoryverbs>
<weight type="int">5</weight>
<speed type="int">6</speed>
<damage type="int">2</damage>
<damage_type>bludgeoning</damage_type>
</object>
</object>
<object name="The western path">
<inherit name="editor_room" />
<alias>path going west</alias>
<usedefaultprefix type="boolean">false</usedefaultprefix>
<prefix>a</prefix>
<exit alias="east" to="The Clearing">
<inherit name="eastdirection" />
</exit>
<object name="Delvas">
<inherit name="editor_object" />
<ask type="scriptdictionary">
<item key="joining">
msg ("Sure, I'll join you. I am good at melee fighting.")
if (Ask("Do you want me to join you?")) {
list add (Followers, Delvas)
}
</item>
</ask>
</object>
</object>
<object name="Beginning">
<inherit name="editor_room" />
<descprefix type="string"></descprefix>
<objectslistprefix type="string"></objectslistprefix>
<usedefaultprefix type="boolean">false</usedefaultprefix>
<exitslistprefix type="string"></exitslistprefix>
<firstenter type="script"><![CDATA[
Followers = NewObjectList()
msg ("You wake up with amnesia in an unfamiliar location. Your memories are limited to your name and your profession.")
msg ("What is your name?")
player.player_name = GetInput()
msg (">"+player.player_name)
msg ("What race are you? You can be an elf, a dwarf, or a dwarf.")
player.race = GetInput()
msg (">"+player.race)
while (player.race <> "elf" and player.race <> "dwarf" and player.race <> "human") {
msg ("That is not a valid race. Please select again.")
player.race = GetInput()
msg (">"+player.race)
}
MoveObject (player, The Clearing)
]]></firstenter>
<object name="player">
<inherit name="defaultplayer" />
<race type="string"></race>
<player_name type="string"></player_name>
</object>
</object>
<command>
<pattern>wield</pattern>
</command>
<function name="NPCMove" parameters="Followers">
foreach (NPC, Followers) {
NPC.parent = player.parent
}
</function>
</asl>

Alex
You've got "Followers" as a local variable in your game start script, and your Beginning "first enter" script. It won't be available to your The Clearing "enter" script.

Either declare another local variable in the "enter" script, or use an attribute instead (e.g. use "game.Followers")

Garan
Ah, I see. I added "game." to anywhere I referred to the list, and it works the way I want it to now. I tested it, and Delvas did follow me back to The Clearing.

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

Support

Forums