Help with Wandering Npcs
Talon
04 Jun 2016, 22:12Been working a bit on a patrolling character that will randomly move around the game, seeing if things are amiss and such.. I've had two ideas I'm trying, not getting much progress on either.. Hope this is clear enough explained
1 first trying to use a function from the library area of this site
(viewtopic.php?f=18&t=5614) RandomNextUnlockedRoom function
But..honestly have no idea what to start with, have tried putting the parameters as the room the patroler is in, but that didn't seem to work... I've never really played around much with functions like this , do i use the call function as part of an experession? or the function from the script menu...
2. I'm trying a similar idea to make the patroler randomly moveform one room to another, I know i COULD do it with using a random number and set up alot of if statements, but i was looking for something more elegant in design.. mainly since i have all the rooms in a organizational room(Private Rooms) in this case, I was thinking i could use something involving making a object list based on getalldirectchildren function.. but i don't know how to actually "Use" the function.
In the end i'd like it to automatically take a number from the list, correspond it to the list of rooms and move the NPC to the appropriate random room
1 first trying to use a function from the library area of this site
(viewtopic.php?f=18&t=5614) RandomNextUnlockedRoom function
But..honestly have no idea what to start with, have tried putting the parameters as the room the patroler is in, but that didn't seem to work... I've never really played around much with functions like this , do i use the call function as part of an experession? or the function from the script menu...
2. I'm trying a similar idea to make the patroler randomly moveform one room to another, I know i COULD do it with using a random number and set up alot of if statements, but i was looking for something more elegant in design.. mainly since i have all the rooms in a organizational room(Private Rooms) in this case, I was thinking i could use something involving making a object list based on getalldirectchildren function.. but i don't know how to actually "Use" the function.
In the end i'd like it to automatically take a number from the list, correspond it to the list of rooms and move the NPC to the appropriate random room
HegemonKhan
04 Jun 2016, 23:13I haven't looked at Pixie's Library, and it's a much better/efficient design than anything I could do, so, I'll just try to help you with the basics of this stuff.
you're going to have to work with List Attributes, as these allow you to iterate (cycle) through multiple items (such as rooms you want a npc to move amongst them). here's a guide of mine on using List and Dictionary Attributes: viewtopic.php?f=18&t=5137
iteration is done through mainly the 'foreach' Function: http://docs.textadventures.co.uk/quest/ ... reach.html
For doing any randomized movement/selection, you got to use/create a "randomizing" math equation. There's 4 built-in such Functions: 'GetRandomInt', GetRandomDouble', 'DiceRoll', and 'RandomChance', or you could always create your own randomization math equation too.
there's two methods for changing an Object's location:
the GUI~Editor's 'MoveObject' Script: http://docs.textadventures.co.uk/quest/ ... bject.html
or
using the built-in 'parent' Object Attribute: http://docs.textadventures.co.uk/quest/ ... arent.html
lastly, indeed if you want/need conditions for what actions you take or don't, you're going to need the 'if' and like Scripts/Funtions, too.
----------
here's one of the simpliest methods of doing randomized movement of an Object, an example (of randomly moving the 'player' Player Object around):
however, you probably don't want to be able to move the 'player' to/into any object in the game, lol. Thus, we need to add some conditions...
we only want to be able to move the 'player' into rooms:
but let's say we want to randomly select one of the 'pcs' (player or HK or Talon) to randomly move into rooms:
the code still has some issues to address, but it was just an example.
-------
there's many ways to build/create an ObjectList:
AllObjects() // the lazy way: all objects in the entire game, least efficient obviously, don't use unless have to
the Scopes: http://docs.textadventures.co.uk/quest/scopes.html
GetDirectChildren()
GetAllChildObjects()
or manually build your own
you're going to have to work with List Attributes, as these allow you to iterate (cycle) through multiple items (such as rooms you want a npc to move amongst them). here's a guide of mine on using List and Dictionary Attributes: viewtopic.php?f=18&t=5137
iteration is done through mainly the 'foreach' Function: http://docs.textadventures.co.uk/quest/ ... reach.html
For doing any randomized movement/selection, you got to use/create a "randomizing" math equation. There's 4 built-in such Functions: 'GetRandomInt', GetRandomDouble', 'DiceRoll', and 'RandomChance', or you could always create your own randomization math equation too.
there's two methods for changing an Object's location:
the GUI~Editor's 'MoveObject' Script: http://docs.textadventures.co.uk/quest/ ... bject.html
or
using the built-in 'parent' Object Attribute: http://docs.textadventures.co.uk/quest/ ... arent.html
lastly, indeed if you want/need conditions for what actions you take or don't, you're going to need the 'if' and like Scripts/Funtions, too.
----------
here's one of the simpliest methods of doing randomized movement of an Object, an example (of randomly moving the 'player' Player Object around):
<turnscript name="global_turnscript">
<enabled />
<script>
randomized_movement_function (player)
</script>
</turnscript>
// the 'player' is the 'argument' inside of the parenthesis of the 'randomized_movement_function()' Function, which is stored into the 'moving_object_parameter' Parameter VARIABLE, which can then be used in the Function's scripting
// moving_object_parameter = player
// so, you can change what Object you want to be moving, via changing what you put into the Fucntion's argument, for example:
// randomized_movement_function (HK)
// moving_object_parameter = HK
// -------------------
// in the GUI~Editor, for using Functions:
// you'd choose the 'call function' Script choice: in/for your (global) turnscript -> add new script -> 'call function' Script
// and you type in the Function's name into the text box, and if you have/need any arguments-parameters, you add them using the 'add' parameter' button.
// of course you got to create the Function itself as well.
// ----------------
<function name="randomized_movement_function" parameters="moving_object_parameter">
all_objects_objectlist_variable = AllObjects()
random_selection_destination_object_variable = ObjectListItem (all_objects_objectlist_variable, GetRandomInt (0, ListCount (all_objects_objectlist_variable) - 1)))
moving_object_parameter.parent = random_selection_destination_object_variable
</function>
however, you probably don't want to be able to move the 'player' to/into any object in the game, lol. Thus, we need to add some conditions...
we only want to be able to move the 'player' into rooms:
<object name="room1">
<attr name="type_of_object_string_attribute" type="string">room</attr>
</object>
<object name="room2">
<attr name="type_of_object_string_attribute" type="string">room</attr>
</object>
<object name="room3">
<attr name="type_of_object_string_attribute" type="string">room</attr>
</object>
<object name="npc1">
<attr name="type_of_object_string_attribute" type="string">npc</attr>
</object>
<object name="npc2">
<attr name="type_of_object_string_attribute" type="string">room</attr>
</object>
<object name="tree1">
<attr name="type_of_object_string_attribute" type="string">tree</attr>
</object>
<object name="monster1">
<attr name="type_of_object_string_attribute" type="string">monster</attr>
</object>
<object name="player">
<attr name="type_of_object_string_attribute" type="string">pc</attr>
</object>
<object name="HK">
<attr name="type_of_object_string_attribute" type="string">pc</attr>
</object>
<turnscript name="global_turnscript">
<enabled />
<script>
randomized_movement_function (player)
</script>
</turnscript>
<function name="randomized_movement_function" parameters="moving_object_parameter">
all_objects_objectlist_variable = AllObjects()
random_selection_destination_object_variable = ObjectListItem (all_objects_objectlist_variable, GetRandomInt (0, ListCount (all_objects_objectlist_variable) - 1)))
if (GetString (random_selection_destination_object_variable, "type_of_object_string_attribute") = "room") {
moving_object_parameter.parent = random_selection_destination_object_variable
}
</function>
but let's say we want to randomly select one of the 'pcs' (player or HK or Talon) to randomly move into rooms:
<object name="room1">
<attr name="type_of_object_string_attribute" type="string">room</attr>
</object>
<object name="room2">
<attr name="type_of_object_string_attribute" type="string">room</attr>
</object>
<object name="room3">
<attr name="type_of_object_string_attribute" type="string">room</attr>
</object>
<object name="npc1">
<attr name="type_of_object_string_attribute" type="string">npc</attr>
</object>
<object name="npc2">
<attr name="type_of_object_string_attribute" type="string">room</attr>
</object>
<object name="tree1">
<attr name="type_of_object_string_attribute" type="string">tree</attr>
</object>
<object name="monster1">
<attr name="type_of_object_string_attribute" type="string">monster</attr>
</object>
<object name="player">
<attr name="type_of_object_string_attribute" type="string">pc</attr>
</object>
<object name="HK">
<attr name="type_of_object_string_attribute" type="string">pc</attr>
</object>
<object name="Talon">
<attr name="type_of_object_string_attribute" type="string">pc</attr>
</object>
<turnscript name="global_turnscript">
<enabled />
<script>
random_selection_pc_object_variable = randomized_pc_selection_function()
randomized_movement_function (random_selection_pc_object_variable)
</script>
</turnscript>
<function name="randomized_pc_selection_function" type="object">
all_objects_objectlist_variable = AllObjects()
random_selection_pc_object_variable = ObjectListItem (all_objects_objectlist_variable, GetRandomInt (0, ListCount (all_objects_objectlist_variable) - 1)))
if (GetString (random_selection_pc_object_variable, "type_of_object_string_attribute") = "pc") {
return (random_selection_pc_object_variable)
}
</function>
<function name="randomized_movement_function" parameters="moving_object_parameter">
all_objects_objectlist_variable = AllObjects()
random_selection_destination_object_variable = ObjectListItem (all_objects_objectlist_variable, GetRandomInt (0, ListCount (all_objects_objectlist_variable) - 1)))
if (GetString (random_selection_destination_object_variable, "type_of_object_string_attribute") = "room") {
moving_object_parameter.parent = random_selection_destination_object_variable
}
</function>
the code still has some issues to address, but it was just an example.
-------
there's many ways to build/create an ObjectList:
AllObjects() // the lazy way: all objects in the entire game, least efficient obviously, don't use unless have to
the Scopes: http://docs.textadventures.co.uk/quest/scopes.html
GetDirectChildren()
GetAllChildObjects()
or manually build your own

XanMag
04 Jun 2016, 23:32EDIT: I hope you didn't stumble on to my last idiotic post before I edited this one!
Here is a working example of a wandering Patroller. There probably is an more streamlined solution to this, but here is what I came up with. NOTE: THIS IS A CYCLICAL/PERIODIC ROTATION. I will post a random rotation later.
And here is the .aslx file if interested (or easier to use).
Essentially what I did:
1. Add an attribute to the Patroller <-- that was my object I wanted to move randomly.
2. Select Integer.
3. Set it to 0 (zero).
4. Click on Add Change Script. Note its name is 'changedPatrolCount'.
5. Add an 'If' Script to this changed script.
6. To the 'If' part of this script, select from the drop-down menu 'if object attribute equals'.
7. Change the object to 'Patroller'. Change the attribute to 'PatrolCount'. Set that equal to 1.
8. For the 'Then' part of the add a 'Move Object' script. Move object 'Patroller' to the first room in your list. Mine was simply named 'room'. Also add whatever other script you want to include here. I added a message indicating the Patroller had changed rooms.
9. Add a script to the 'Else If' part of this script. Repeat step 6-8, changing the bold 1 in step 7. Change this to a number whose difference to the previous PatrolCount is equal to how long you want the Patroller to stay in said room. Also change the move object Patroller to whatever the next room on the list is.
10. Copy-Paste step 9 for however many rooms you want the Patroller to cycle through.
11. For the last 'Else If', Set Variable Patroller.PatrolCount = 0. This will start the cycle over again.

Here is a working example of a wandering Patroller. There probably is an more streamlined solution to this, but here is what I came up with. NOTE: THIS IS A CYCLICAL/PERIODIC ROTATION. I will post a random rotation later.
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Patrolling Test">
<gameid>3400b74c-78f4-4ee5-ae49-46159b4b1d51</gameid>
<version>1.0</version>
<firstpublished>2016</firstpublished>
<start type="script">
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="east" to="room 2">
<inherit name="eastdirection" />
</exit>
<exit alias="south" to="room 4">
<inherit name="southdirection" />
</exit>
</object>
<object name="room 2">
<inherit name="editor_room" />
<exit alias="west" to="room">
<inherit name="westdirection" />
</exit>
<exit alias="south" to="room 3">
<inherit name="southdirection" />
</exit>
</object>
<object name="room 3">
<inherit name="editor_room" />
<exit alias="north" to="room 2">
<inherit name="northdirection" />
</exit>
<exit alias="west" to="room 4">
<inherit name="westdirection" />
</exit>
</object>
<object name="room 4">
<inherit name="editor_room" />
<object name="Patroller">
<inherit name="editor_object" />
<PatrolCount type="int">0</PatrolCount>
<changedPatrolCount type="script">
if (Patroller.PatrolCount = 1) {
MoveObject (Patroller, room)
msg ("The Patroller has changed rooms!")
}
else if (Patroller.PatrolCount = 4) {
MoveObject (Patroller, room 2)
msg ("The Patroller has changed rooms!")
}
else if (Patroller.PatrolCount = 7) {
MoveObject (Patroller, room 3)
msg ("The Patroller has changed rooms!")
}
else if (Patroller.PatrolCount = 10) {
MoveObject (Patroller, room 4)
msg ("The Patroller has changed rooms!")
}
else if (Patroller.PatrolCount = 12) {
Patroller.PatrolCount = 0
}
</changedPatrolCount>
</object>
<exit alias="east" to="room 3">
<inherit name="eastdirection" />
</exit>
<exit alias="north" to="room">
<inherit name="northdirection" />
</exit>
</object>
<turnscript name="Patroller TS">
<enabled />
<script>
Patroller.PatrolCount = Patroller.PatrolCount +1
</script>
</turnscript>
<turnscript name="Patroller Visible">
<enabled />
<script>
if (ListContains(ScopeVisible(), Patroller)) {
if (Patroller.PatrolCount = 4) {
msg ("The Patroller has wandered into your room!")
}
else if (Patroller.PatrolCount = 7) {
msg ("The Patroller has wandered into your room!")
}
else if (Patroller.PatrolCount = 10) {
msg ("The Patroller has wandered into your room!")
}
else if (Patroller.PatrolCount = 1) {
msg ("The Patroller has wandered into your room!")
}
else {
msg ("The Patroller is milling around the room, eyeing you with suspicion.")
}
}
</script>
</turnscript>
</asl>
And here is the .aslx file if interested (or easier to use).
Essentially what I did:
1. Add an attribute to the Patroller <-- that was my object I wanted to move randomly.
2. Select Integer.
3. Set it to 0 (zero).
4. Click on Add Change Script. Note its name is 'changedPatrolCount'.
5. Add an 'If' Script to this changed script.
6. To the 'If' part of this script, select from the drop-down menu 'if object attribute equals'.
7. Change the object to 'Patroller'. Change the attribute to 'PatrolCount'. Set that equal to 1.
8. For the 'Then' part of the add a 'Move Object' script. Move object 'Patroller' to the first room in your list. Mine was simply named 'room'. Also add whatever other script you want to include here. I added a message indicating the Patroller had changed rooms.
9. Add a script to the 'Else If' part of this script. Repeat step 6-8, changing the bold 1 in step 7. Change this to a number whose difference to the previous PatrolCount is equal to how long you want the Patroller to stay in said room. Also change the move object Patroller to whatever the next room on the list is.
10. Copy-Paste step 9 for however many rooms you want the Patroller to cycle through.
11. For the last 'Else If', Set Variable Patroller.PatrolCount = 0. This will start the cycle over again.

XanMag
05 Jun 2016, 02:28Here is a sample for a random room change for an NPC. Again, there's likely a better way to streamline this, but here you go.
Here is the global turnscript I placed in the game-script tab. It's separate because I joined both of these examples in the same file.
Here is the .aslx file with both of them together if that makes it easier to understand.
To save myself (and likely you) from further descriptions... I did essentially the same thing as my previous post. I added a turn counter that reset at 4. I added a script dictionary and named it RandomPatrol. The keys were numbered 1-x (x being the number of room you want patrolled). The scripts were copy-paste bits moving the patrolling NPC to a room (just got to change the room) I also added in this script if the patroller was moved into a room that contained the player, a message indicating that was printed.. On count three, I ran that complicated bit:
to call the script dictionary at random. It may seem like a lot when you have a bunch of rooms, but once you get the copy-paste-change that bit for each of the items in the script dictionary, it goes VERY fast. A few minutes and you can do 50 rooms pretty easy (once you get the hang of it).
If you need help with a further explanation, let me know.
<object name="room A">
<inherit name="editor_room" />
<exit alias="east" to="room B">
<inherit name="eastdirection" />
</exit>
<exit alias="south" to="room D">
<inherit name="southdirection" />
</exit>
<object name="Patroller Random">
<inherit name="editor_object" />
<PatrolCount2 type="int">0</PatrolCount2>
<RandomPatrol type="scriptdictionary">
<item key="1">
MoveObject (Patroller Random, room A)
if (game.pov.parent = room A) {
msg ("The Random Patroller has wandered into your room!")
}
</item>
<item key="2">
MoveObject (Patroller Random, room B)
if (game.pov.parent = room B) {
msg ("The Random Patroller has wandered into your room!")
}
</item>
<item key="3">
MoveObject (Patroller Random, room C)
if (game.pov.parent = room C) {
msg ("The Random Patroller has wandered into your room!")
}
</item>
<item key="4">
MoveObject (Patroller Random, room D)
if (game.pov.parent = room D) {
msg ("The Random Patroller has wandered into your room!")
}
</item>
</RandomPatrol>
<changedPatrolCount2 type="script">
if (Patroller Random.PatrolCount2 = 3) {
n = ToString (GetRandomInt (1, DictionaryCount (Patroller Random.RandomPatrol)))
m = ScriptDictionaryItem(Patroller Random.RandomPatrol, n)
invoke (m)
}
else if (Patroller Random.PatrolCount2 = 4) {
Patroller Random.PatrolCount2 = 1
}
</changedPatrolCount2>
</object>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="north" to="room 4">
<inherit name="northdirection" />
</exit>
</object>
<object name="room B">
<inherit name="editor_room" />
<exit alias="west" to="room A">
<inherit name="westdirection" />
</exit>
<exit alias="south" to="room C">
<inherit name="southdirection" />
</exit>
</object>
<object name="room C">
<inherit name="editor_room" />
<exit alias="north" to="room B">
<inherit name="northdirection" />
</exit>
<exit alias="west" to="room D">
<inherit name="westdirection" />
</exit>
</object>
<object name="room D">
<inherit name="editor_room" />
<exit alias="east" to="room C">
<inherit name="eastdirection" />
</exit>
<exit alias="north" to="room A">
<inherit name="northdirection" />
</exit>
</object>
</asl>
Here is the global turnscript I placed in the game-script tab. It's separate because I joined both of these examples in the same file.
<turnscript name="Patroller TS">
<enabled />
<script>
Patroller.PatrolCount = Patroller.PatrolCount +1
Patroller Random.PatrolCount2 = Patroller Random.PatrolCount2 +1
</script>
</turnscript>
Here is the .aslx file with both of them together if that makes it easier to understand.
To save myself (and likely you) from further descriptions... I did essentially the same thing as my previous post. I added a turn counter that reset at 4. I added a script dictionary and named it RandomPatrol. The keys were numbered 1-x (x being the number of room you want patrolled). The scripts were copy-paste bits moving the patrolling NPC to a room (just got to change the room) I also added in this script if the patroller was moved into a room that contained the player, a message indicating that was printed.. On count three, I ran that complicated bit:
if (Patroller Random.PatrolCount2 = 3) {
n = ToString (GetRandomInt (1, DictionaryCount (Patroller Random.RandomPatrol)))
m = ScriptDictionaryItem(Patroller Random.RandomPatrol, n)
invoke (m)
}
to call the script dictionary at random. It may seem like a lot when you have a bunch of rooms, but once you get the copy-paste-change that bit for each of the items in the script dictionary, it goes VERY fast. A few minutes and you can do 50 rooms pretty easy (once you get the hang of it).
If you need help with a further explanation, let me know.
The Pixie
05 Jun 2016, 08:14Talon wrote:1 first trying to use a function from the library area of this site
(viewtopic.php?f=18&t=5614) RandomNextUnlockedRoom function
But..honestly have no idea what to start with, have tried putting the parameters as the room the patroler is in, but that didn't seem to work... I've never really played around much with functions like this , do i use the call function as part of an experession? or the function from the script menu...
To put the function in your game, go to Functions in the left pane, then click add, give it the name RandomNextUnlockedRoom.
Set the return type to "Object", and add "currentroom" as a paramter. Go into code view, and paste the code in:
exts = ScopeUnlockedExitsForRoom (currentroom)
if (ListCount(exts) = 0) {
return (currentroom)
}
exit = ObjectListItem(exts, GetRandomInt(0, ListCount(exts) - 1))
return (exit.to)
You also need the ScopeUnlockedExitsForRoom functions, so do Add again, and this time call it ScopeUnlockedExitsForRoom. Set the return type to "ObjectList" this time, and add "room" as a paramter. Go into code view, and paste the code in:
result = NewObjectList()
foreach (exit, ScopeExitsForRoom(room)) {
if (exit.visible and not exit.locked) {
if (GetBoolean(room, "darklevel")) {
if (GetBoolean(exit, "lightsource")) {
list add (result, exit)
}
}
else {
list add (result, exit)
}
}
}
return (result)
For your NPCs, you invoke the function like this (the parent of an object is its location):
my_npc.parent = RandomNextUnlockedRoom(my_npc.parent)
2. I'm trying a similar idea to make the patroler randomly moveform one room to another, I know i COULD do it with using a random number and set up alot of if statements, but i was looking for something more elegant in design.. mainly since i have all the rooms in a organizational room(Private Rooms) in this case, I was thinking i could use something involving making a object list based on getalldirectchildren function.. but i don't know how to actually "Use" the function.
In the end i'd like it to automatically take a number from the list, correspond it to the list of rooms and move the NPC to the appropriate random room
Exits are different to objects, kind of. GetAllDirectChildren will get the objects, not the exits, so I used ScopeExitsForRoom above. But exits are kind of objects, so you can store them in an object list...
If you want to restrict your NPCs to a set of rooms, like one organizational room, you can modify the script in the ScopeUnlockedExitsForRoom function.
Talon
05 Jun 2016, 11:08Wow this looks like some great stuff in the replies, will have to read over them and digest them before trying them out but thanks to everyone in advance, its amazing how friendly folks are here as i struggle to learn and test my limits into my first baby steps of programming.
*edit* Thank you so much Pixie, that was a extremely helpful explanation, Things are moving and i can work and tune it to my needs. Also going to read up and try to absorb all the other help people have posted, just so much info I can work to add so i truly understand what i'm working with, heck perhaps some day i'll be able to answer questions for new users as well
*edit* Thank you so much Pixie, that was a extremely helpful explanation, Things are moving and i can work and tune it to my needs. Also going to read up and try to absorb all the other help people have posted, just so much info I can work to add so i truly understand what i'm working with, heck perhaps some day i'll be able to answer questions for new users as well

jaynabonne
06 Jun 2016, 06:57Not sure if this would be helpful or not, but I wrote a "path" library long ago, where you give it a source and destination, and it computes the exits you need to traverse to get from one to the other.
viewtopic.php?f=18&t=3214
I'm only suggesting it as an alternative to the "wander aimlessly randomly in the overall map, even it means possibly going back and forth between two rooms". With the path library, you'd have definite "target" rooms for your NPC. Rather than selecting a random next direction, you could pick a random next target room, and then follow the path to it. When you arrive there, you could pick a next random target - or set up regular patrols or whatever you like.
Again, just an alternative.
viewtopic.php?f=18&t=3214
I'm only suggesting it as an alternative to the "wander aimlessly randomly in the overall map, even it means possibly going back and forth between two rooms". With the path library, you'd have definite "target" rooms for your NPC. Rather than selecting a random next direction, you could pick a random next target room, and then follow the path to it. When you arrive there, you could pick a next random target - or set up regular patrols or whatever you like.
Again, just an alternative.

Talon
06 Jun 2016, 11:32Will Take a look at it, even if I don't use it I want to improve my confidence with systems, seeing more code can only help that, currently not sure I'd use it, though perhaps i'll put some sort of monster that chases the player down to practice with it at least.
-Edit-Works very well on the test, admittedly I have to find a more reliably way of slowing up the patrol, taking one step every time the player does is way to fast, for the moment i'm using the stopgap method of having the function fire only 20% of the time thanks to an if/random script..
Kinda think i could do it better with a something for or foreach but don't understand those enough to use em properly....
Suppose that brings another question, is there a non chance way increase the number of steps in a turnscript for a script to fire(lets say one move for every 3 the player takes, otherwise escaping anything chasing you is going to be REALLY hard.
-Edit-Works very well on the test, admittedly I have to find a more reliably way of slowing up the patrol, taking one step every time the player does is way to fast, for the moment i'm using the stopgap method of having the function fire only 20% of the time thanks to an if/random script..
Kinda think i could do it better with a something for or foreach but don't understand those enough to use em properly....
Suppose that brings another question, is there a non chance way increase the number of steps in a turnscript for a script to fire(lets say one move for every 3 the player takes, otherwise escaping anything chasing you is going to be REALLY hard.

jaynabonne
06 Jun 2016, 15:18If you have a turn counter that you increment on each turn, then you have could have in your turn script:
if (game.turns % 3 = 0)
// do the movement
That's the "mod" operator, which returns the remainder. So it would move on turn 0, 3, 6, 9, etc.
if (game.turns % 3 = 0)
// do the movement
That's the "mod" operator, which returns the remainder. So it would move on turn 0, 3, 6, 9, etc.
Talon
06 Jun 2016, 16:07that way would work nicely i think, hadn't thought of setting up a turn counter just like that in the background to handle it. Still working on setting up a few destinations in the path too
And i also now know what Modular Arithmetic is, learn something new every day
And i also now know what Modular Arithmetic is, learn something new every day
HegemonKhan
06 Jun 2016, 21:48humans can find the quotient and remainder of a division operation at the same time, but to do this in programming, they're two separate operations, one to find the quotient and one to find the remainder, so that's why in programming, you also got a 'modulus' operator/operation, which many people don't know of/about (including me, I just like you were informed of it by Jay too, laughs).
-------
the 'modulus' operator: %, is the same as a division: /, operation, except it finds/return/gets the remainder, and NOT the quotient.
is great for 'cyclic' counting, such as examples of: 0-59 sec/min clock time, 0-11/0-23 hrs clock time, 0-28/0-29/0-30/0-31 days in a month, 0-7 days in a week, etc etc etc.
also, you can use it for other fancy things, such as if a number is odd or even, too.
-------
player.strength = 100
player.strength = player.stength / 10
// player.strength = 100 / 10 = 10
~ VS ~
player.strength = player.strength % 10
// player.strength = 100 % 10 = R: 0
player.strength = 0
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 0
player.strength = 1
player.strength = player.strength % 10
// player.strength = 1 % 10 = R: 1
player.strength = 9
player.strength = player.strength % 10
// player.strength = 9 % 10 = R: 9
player.strength = 10
player.strength = player.strength % 10
// player.strength = 10 % 10 = R: 0
player.strength = 11
player.strength = player.strength % 10
// player.strength = 11 % 10 = R: 1
player.strength = 49
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 9
player.strength = 51
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 1
player.strength = 99
player.strength = player.strength % 10
// player.strength = 99 % 10 = R: 9
player.strength = 100
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 0
player.strength = 101
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 1
-----
if (player.strength % 2 = 0) { msg ("The player's strength is an even number") } else { msg ("The player's strength is an odd number.") }
// 100 % 2 = R: 0 -> divisible by 2: 100 is an even number
// 101 % 2 = R: 1 -> NOT divisible by 2: 101 is an odd number
// 43284739841386486 % 2 = R: 0 -> 43284739841386486 is an even number
// 348947189476927 % 2 = R: 1 -> 348947189476927 is an odd number
// any number divisible by 2 (having no/zero remainder), is an even number
if (player.strength % 3 = 0) { msg ("The player's strength is divisible by 3") } else { msg ("The player's strength is not divisible by 3.") }
// 9 % 3 = R: 0 -> divisible by 3
// 8 % 3 = R: 2 -> NOT divisible by 3
// 18 % 3 = R: 0 -> divisible by 3
// 111 % 3 = R: 0 -> divisible by 3
// 110 % 3 = R: 2 -> NOT divisible by 3
// 109 % 3 = R: 1 -> NOT divisible by 3
// 112 % 3 = R: 1 -> NOT divisible by 3
--------------------------------------------
about 'foreach' (iteration through lists) and 'for' (generalized iteration):
--
foreach:
http://docs.textadventures.co.uk/quest/ ... reach.html
see, if this helps with the concept of them:
--------
'for' (generalized iteration) is somewhat the same, except you choose the range (and optionally also the: interval/step), that you want to act upon, and also 'for' doesn't require using a List:
http://docs.textadventures.co.uk/quest/scripts/for.html
an example to add/sum up 0-10 (0+1+2+3+4+5+6+7+8+9+10=?):
(hopefully I've set up this 'for' example correctly, I don't often work much with 'for' in quest, so far anyways)
and you can see an example of 'for' with using a List in this link:
http://docs.textadventures.co.uk/quest/ ... lists.html (scroll down a bit, to about the middle of it)
-------
the 'modulus' operator: %, is the same as a division: /, operation, except it finds/return/gets the remainder, and NOT the quotient.
is great for 'cyclic' counting, such as examples of: 0-59 sec/min clock time, 0-11/0-23 hrs clock time, 0-28/0-29/0-30/0-31 days in a month, 0-7 days in a week, etc etc etc.
also, you can use it for other fancy things, such as if a number is odd or even, too.
-------
player.strength = 100
player.strength = player.stength / 10
// player.strength = 100 / 10 = 10
~ VS ~
player.strength = player.strength % 10
// player.strength = 100 % 10 = R: 0
player.strength = 0
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 0
player.strength = 1
player.strength = player.strength % 10
// player.strength = 1 % 10 = R: 1
player.strength = 9
player.strength = player.strength % 10
// player.strength = 9 % 10 = R: 9
player.strength = 10
player.strength = player.strength % 10
// player.strength = 10 % 10 = R: 0
player.strength = 11
player.strength = player.strength % 10
// player.strength = 11 % 10 = R: 1
player.strength = 49
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 9
player.strength = 51
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 1
player.strength = 99
player.strength = player.strength % 10
// player.strength = 99 % 10 = R: 9
player.strength = 100
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 0
player.strength = 101
player.strength = player.strength % 10
// player.strength = 0 % 10 = R: 1
-----
if (player.strength % 2 = 0) { msg ("The player's strength is an even number") } else { msg ("The player's strength is an odd number.") }
// 100 % 2 = R: 0 -> divisible by 2: 100 is an even number
// 101 % 2 = R: 1 -> NOT divisible by 2: 101 is an odd number
// 43284739841386486 % 2 = R: 0 -> 43284739841386486 is an even number
// 348947189476927 % 2 = R: 1 -> 348947189476927 is an odd number
// any number divisible by 2 (having no/zero remainder), is an even number
if (player.strength % 3 = 0) { msg ("The player's strength is divisible by 3") } else { msg ("The player's strength is not divisible by 3.") }
// 9 % 3 = R: 0 -> divisible by 3
// 8 % 3 = R: 2 -> NOT divisible by 3
// 18 % 3 = R: 0 -> divisible by 3
// 111 % 3 = R: 0 -> divisible by 3
// 110 % 3 = R: 2 -> NOT divisible by 3
// 109 % 3 = R: 1 -> NOT divisible by 3
// 112 % 3 = R: 1 -> NOT divisible by 3
--------------------------------------------
about 'foreach' (iteration through lists) and 'for' (generalized iteration):
--
foreach:
http://docs.textadventures.co.uk/quest/ ... reach.html
see, if this helps with the concept of them:
// Object Type (quest's 'classes/groups' usage, at least at the user level anyways):
<type name="team_object_type">
<attr name="run_laps" type="script">
msg (this.name + " runs laps.")
</attr>
</type>
// the (probably) needed Verb-required extra code for the 'run_laps' Script Attributes:
<verb>
<property>run_laps</property>
<pattern>run_laps</pattern>
<defaultexpression>That can't run laps!</defaultexpression>
</verb>
// the Objects:
<object name="player">
<inherit name="team_object_type" />
</object>
<object name="HK">
<inherit name="team_object_type" />
</object>
<object name="Talon">
<inherit name="team_object_type" />
</object>
<object name="Jay">
<inherit name="team_object_type" />
</object>
<object name="Matt">
<inherit name="team_object_type" />
</object>
<object name="Mike">
<inherit name="team_object_type" />
</object>
<object name="Joe">
<inherit name="team_object_type" />
</object>
<object name="Jeff">
<inherit name="team_object_type" />
</object>
// game.team is an Object List Attribute (unfortunately you can't directly create an Object List Attribute in the GUI~Editor), created in this case through the 'split' Script/Function:
game.team = split ("player; HK; Talon; Jay; Mike; Matt; Joe; Jeff", ";")
// iterating through the items in the List, and having EACH/EVERY/ALL (for*EACH*) of them execute/run/activate an order/action/event (a Script Attribute of theirs in this case/example):
foreach (team_member, game.team) {
// my 'team_member' is just the name/label I'm using for the 'placeholder' Variable, which each item is stored and used as, by the scripting, one after the other
// you can also use the 'do' Script/Function (and it's a bit more powerful than the 'invoke' Script/Function, if you need such functionality, but for just activating a Script Attribute, which is what a GUI~Editor's 'Verb' is btw, 'invoke' works fine)
invoke (team_member.run_laps)
// team_member = player -> invoke (player.run_laps)
// team_member = HK -> invoke (HK.run_laps)
// team_member = Talon -> invoke (Talon.run_laps)
// team_member = Jay -> invoke (Jay.run_laps)
// team_member = Mike -> invoke (Mike.run_laps)
// team_member = Matt -> invoke (Matt.run_laps)
// team_member = Joe -> invoke (Joe.run_laps)
// team_member = Jeff -> invoke (Jeff.run_laps)
}
// output:
player runs laps.
HK runs laps.
Talon runs laps.
Jay runs laps.
Mike runs laps.
Matt runs laps.
Joe runs laps.
Jeff runs laps.
--------
'for' (generalized iteration) is somewhat the same, except you choose the range (and optionally also the: interval/step), that you want to act upon, and also 'for' doesn't require using a List:
http://docs.textadventures.co.uk/quest/scripts/for.html
an example to add/sum up 0-10 (0+1+2+3+4+5+6+7+8+9+10=?):
(hopefully I've set up this 'for' example correctly, I don't often work much with 'for' in quest, so far anyways)
sum = 0
for (x, 1, 10, 1) {
sum = sum + x
}
msg ("The sum of 0-10 is: " + sum)
// output: The sum of 0-10 is: 55
and you can see an example of 'for' with using a List in this link:
http://docs.textadventures.co.uk/quest/ ... lists.html (scroll down a bit, to about the middle of it)