<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><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><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><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> <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> <turnscript name="Patroller TS">
<enabled />
<script>
Patroller.PatrolCount = Patroller.PatrolCount +1
Patroller Random.PatrolCount2 = Patroller Random.PatrolCount2 +1
</script>
</turnscript>if (Patroller Random.PatrolCount2 = 3) {
n = ToString (GetRandomInt (1, DictionaryCount (Patroller Random.RandomPatrol)))
m = ScriptDictionaryItem(Patroller Random.RandomPatrol, n)
invoke (m)
}Talon 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...
exts = ScopeUnlockedExitsForRoom (currentroom)
if (ListCount(exts) = 0) {
return (currentroom)
}
exit = ObjectListItem(exts, GetRandomInt(0, ListCount(exts) - 1))
return (exit.to) 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)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
// 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.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