better way to implementing a car?
ELGAROU
05 Feb 2014, 20:15I make this question because I'm trying to implement a car in my game, and even when I can manage to move the player from one room to another using the "show menu"script, this just output the "result" variable that is only a string, then I have to implement a nested "if" script to match the selection of the menu with the "result" variable and then be able to move the player to certain room. this works but I wonder if is a better way to do it.
So I realized that atributes can“t be objectlist type (at least directly to the gui options) why is that?? I wonder if through the use of objectlists things will be "smoother" in terms of coding.
I saw in the wiki the elevator library and suppose that including it in my game will allow to achieve what I want.
Anyway Maybe sounds confusing but I hope someone could help me to understand this.
Greetings.
So I realized that atributes can“t be objectlist type (at least directly to the gui options) why is that?? I wonder if through the use of objectlists things will be "smoother" in terms of coding.
I saw in the wiki the elevator library and suppose that including it in my game will allow to achieve what I want.
Anyway Maybe sounds confusing but I hope someone could help me to understand this.
Greetings.
Entropic Pen
06 Feb 2014, 00:53Yeah, that "can't make an ObjectList as an object attribute via the GUI" is annoying. But anyway I'm guessing you want to make a menu showing different destinations that the character will "drive to"... and I have something you can look at over at:
http://forum.textadventures.co.uk/viewtopic.php?f=18&t=4025 with the "rand_pagemenu" function in the "ta_gb_hybrid" demo. There's plenty of instructions in that demo that'll tell you how it works.
But if you do want to use "ObjectLists" in the way you want it to make things go smoother... then do it. Making a show menu is elementary (compared to the many things I had to do in "Entropic Adventure":
Here is a "car_menu" function so you wouldn't have to copy-and-paste this code over and over again:
parameters = "location_list"
To use this code, take this and put it into anywhere you need it to be:
http://forum.textadventures.co.uk/viewtopic.php?f=18&t=4025 with the "rand_pagemenu" function in the "ta_gb_hybrid" demo. There's plenty of instructions in that demo that'll tell you how it works.
But if you do want to use "ObjectLists" in the way you want it to make things go smoother... then do it. Making a show menu is elementary (compared to the many things I had to do in "Entropic Adventure":
Here is a "car_menu" function so you wouldn't have to copy-and-paste this code over and over again:
parameters = "location_list"
game.carmenu_list = location_list
temp_list = NewStringList()
foreach (o, game.carmenu_list) {
list add (temp_list, o.alias)
}
list add (temp_list, "(Nevermind)")
ShowMenu ("", temp_list, false) {
if (result <> "(Nevermind)") {
got_item = 0
count = 0
foreach (o, game.carmenu_list) {
if (o.alias = result) {
got_item = count
}
count = count +1
}
go_to = ListItem(game.carmenu_list,got_item)
MoveObject (game.pov, go_to)
}
else {
msg ("You decided to not go anywhere")
}
}
To use this code, take this and put it into anywhere you need it to be:
location_list = NewObjectList()
list add (location_list, area1)
list add (location_list, area2)
list add (location_list, area3)
car_menu (location_list)
ELGAROU
06 Feb 2014, 04:36First of all, thanks for your response.
I read the code you pasted and also downloaded the random page demo, anyway I'm a begginer so right now I can't understand all the thing. tried to copy the code it into my game to see if it works but it just displays an empty list unless for the last option "(Nevermind)".
Even in the case I'm doing something wrong it is not precisely the solution that I was looking for, because there is the issue of entering by hand the locations. I don't specified this before but what I seek is to fill a list through the gameplay, so let say the character go for the first time to a location then that location is added to the list that the "car menu" shows, and so on through the progress of the gameplay.
This can be achieved through the "firstenter" script of each room so I suppose it is not a big problem (even when the optimal would be to implement a script attribute in the player object that add the names to the list when enter for the first time in a room).
In the meantime I manage to solve the whole thing I would to ask why you use the "o" as a parameter for the "for each" script and why you declare "carmenu_list" as a game attribute.
Greetings
I read the code you pasted and also downloaded the random page demo, anyway I'm a begginer so right now I can't understand all the thing. tried to copy the code it into my game to see if it works but it just displays an empty list unless for the last option "(Nevermind)".
Even in the case I'm doing something wrong it is not precisely the solution that I was looking for, because there is the issue of entering by hand the locations. I don't specified this before but what I seek is to fill a list through the gameplay, so let say the character go for the first time to a location then that location is added to the list that the "car menu" shows, and so on through the progress of the gameplay.
This can be achieved through the "firstenter" script of each room so I suppose it is not a big problem (even when the optimal would be to implement a script attribute in the player object that add the names to the list when enter for the first time in a room).
In the meantime I manage to solve the whole thing I would to ask why you use the "o" as a parameter for the "for each" script and why you declare "carmenu_list" as a game attribute.
Greetings
HegemonKhan
06 Feb 2014, 06:31You'll probably need my help with this (and in changing it to your "car" design), but I'm busy until Feb. 14 and can't help you, so you can look over this and see if you can make sense of it (it uses lists and dictionaries which can be daunting for new people), and~or ask someone to help you with my code, or they can just help you themselves with their code or help you via the GUI~Editor.
anyways, here's my own amature "travel" code:
feel free to try~test~play this code~"game" out (look at it in the GUI~Editor, if the code is still too hard for you to understand)
basicallly, you 'explore' (my 'explore' command-function), which randomly chooses an 'event' (a script), which adds that Room Object to your 'travel' list, which you can now move to, using my 'travel' command-function. Now, I got to remove those 'discovery events' (scripts), so they don't occur again, by removing them from the 'explore' list (which is the most complex part of my code, due to using random'ness method of seleting the events), and the 'travel' command-function is, I hope, self-explanatory.
I wrote this code a ways back, and I'm sure I could make it better (shorter code and a more clear~clean code), using script dictionaries, which I didn't realize at the time I did this code.
---------------
http://quest5.net/wiki/Using_Lists
http://quest5.net/wiki/Using_Dictionaries
--------------
http://quest5.net/wiki/Foreach
when you use the "foreach" function, it creates a variable that is set to the contents of the "foreach" string list or object list.
so the "o" (likely stands for "object", other common labels: obj, or my own structure of: adding a "_x" suffix, ie: object_x, item_x, result_x, value_x, and etc), is just that variable.
also, most people don't use "object" as their foreach iteration variable, as it may have conflict with the built-in "object" stuff, or it's just too confusing too, or they're just lazy, as writing "o" or "obj" or "i" (for "item") or "x", is faster, lol.
(object or string) list: soccer ball; football ball; baseball ball; basketball ball
foreach (object_x, global_data_object.sports_ball_object_list) {
-> object_x.play_with
}
conceptually:
for "soccer ball (object_x)", "play with (Verb)" the "soccer ball (object_x)"
for "football ball (object_x)", "play with (Verb)" the "football ball (object_x)"
for "baseball ball (object_x)", "play with (Verb)" the "baseball ball (object_x)"
for "basketball ball (object_x)", "play with (Verb)" the "basketball ball (object_x)"
here's a good example of concept of understanding the "foreach" list iteration function:
foreach (team_member_x, global_data_object.team_members_string_list) {
-> team_member_x.run_four_laps
}
// 'all=every=each' (for*EACH*) team member (team_member_x) of the 'team' (team_members_string_list), has to run 4 laps
---------
http://quest5.net/wiki/For
(lists start from 0, not 1)
(ordering is from left to right)
(soccerball;football;baseball;basketball)
list content 0 = soccerball
list content 1 = football
list content 2 = baseball
list content 3 = basketball
for (object_x, 1,1,1) {
-> object_x.play_with
}
// soccerball
for (object_x, 0,1,1) {
-> object_x.play_with
}
// soccerball and football
for (object_x, 0,2,1) {
-> object_x.play_with
}
// soccerball, football, and baseball
for (object_x, 0,2,2) {
-> object_x.play_with
}
// soccerball and baseball
for (object_x, 1,3,1) {
-> object_x.play_with
}
// football, baseball, and basketball
for (object_x, 1,3,2) {
-> object_x.play_with
}
// football and basketball
for (object_x, 0,3,4) {
-> object_x.play_with
}
// soccer and basketball
----------
by setting ("attaching") an Attribute to an Object, it enables the Attribute to be "permanent~global" ("save'able and load'able").
And, also, if you set the Attribute specifically to the "game" Game Object or to the "player" Player Object or "whatever" Player Object, then you can display those Attributes during game play, via the "status attributes" Attribute (which only works for the "game" Game Object, the "player" Player Object, and "whatever" Player Object).
anyways, here's my own amature "travel" code:
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>eef801a1-4e6b-4b0a-bdbf-8f3ecfa8389c</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
<turns type="int">0</turns>
<statusattributes type="simplestringdictionary">turns=</statusattributes>
<start type="script">
msg ("Important Note:")
msg ("Type in: help")
</start>
</game>
<object name="homeland">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<object name="grassland">
<inherit name="editor_room" />
</object>
<object name="plains">
<inherit name="editor_room" />
</object>
<object name="desert">
<inherit name="editor_room" />
</object>
<object name="tundra">
<inherit name="editor_room" />
</object>
<object name="swampland">
<inherit name="editor_room" />
</object>
<object name="mountains">
<inherit name="editor_room" />
</object>
<object name="forest">
<inherit name="editor_room" />
</object>
<object name="wasteland">
<inherit name="editor_room" />
</object>
<object name="coastland">
<inherit name="editor_room" />
</object>
<object name="hills">
<inherit name="editor_room" />
</object>
<command name="help_command">
<pattern>help</pattern>
<script>
help_function
</script>
</command>
<command name="explore_command">
<pattern>explore</pattern>
<script>
explore_function
</script>
</command>
<command name="travel_command">
<pattern>travel</pattern>
<script>
travel_function
</script>
</command>
<object name="data_object">
<inherit name="editor_object" />
<travel_string_list type="simplestringlist">homeland</travel_string_list>
<homeland_events_string_list type="simplestringlist">grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery</homeland_events_string_list>
<homeland_events_script_dictionary type="scriptdictionary">
<item key="grassland_discovery">
list add (data_object.travel_string_list, "grassland")
msg ("You've discovered the grassland! Now, you can travel to the grassland and explore it!")
</item>
<item key="plains_discovery">
list add (data_object.travel_string_list, "plains")
msg ("You've discovered the plains! Now, you can travel to the plains and explore it!")
</item>
<item key="desert_discovery">
list add (data_object.travel_string_list, "desert")
msg ("You've discovered the desert! Now, you can travel to the desert and explore it!")
</item>
<item key="tundra_discovery">
list add (data_object.travel_string_list, "tundra")
msg ("You've discovered the tundra! Now, you can travel to the tundra and explore it!")
</item>
<item key="swampland_discovery">
list add (data_object.travel_string_list, "swampland")
msg ("You've discovered the swampland! Now, you can travel to the swampland and explore it!")
</item>
<item key="forest_discovery">
list add (data_object.travel_string_list, "forest")
msg ("You've discovered the forest! Now, you can travel to the forest and explore it!")
</item>
<item key="mountains_discovery">
list add (data_object.travel_string_list, "mountains")
msg ("You've discovered the mountains! Now, you can travel to the mountains and explore it!")
</item>
<item key="hills_discovery">
list add (data_object.travel_string_list, "hills")
msg ("You've discovered the hills! Now, you can travel to the hills and explore it!")
</item>
<item key="wasteland_discovery">
list add (data_object.travel_string_list, "wasteland")
msg ("You've discovered the wasteland! Now, you can travel to the wasteland and explore it!")
</item>
<item key="coastland_discovery">
list add (data_object.travel_string_list, "coastland")
msg ("You've discovered the coastland! Now, you can travel to the coastland and explore it!")
</item>
</homeland_events_script_dictionary>
</object>
<turnscript name="global_turnscript">
<enabled />
<script>
game.turns = game.turns + 1
</script>
</turnscript>
<function name="help_function">
msg ("Type 'explore' to explore your area.")
msg ("Type 'travel' to travel to different areas.")
</function>
<function name="explore_function"><![CDATA[
switch (game.pov.parent) {
case (homeland) {
result_1 = ListCount (data_object.homeland_events_string_list) - 1
if (result_1 >= 0) {
result_2 = StringListItem (data_object.homeland_events_string_list,GetRandomInt(0,result_1))
invoke (ScriptDictionaryItem (data_object.homeland_events_script_dictionary,result_2))
on ready {
foreach (item_x, split ("grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery",";")) {
if (result_2 = item_x) {
list remove (data_object.homeland_events_string_list, result_2)
}
}
}
} else {
msg ("There seemingly is nothing left to explore in this area.")
}
}
}
]]></function>
<function name="travel_function">
show menu ("Where do you wish to travel?",data_object.travel_string_list,false) {
if (not game.pov.parent = GetObject (result)) {
game.pov.parent = GetObject (result)
} else {
msg ("You are already at this area.")
ask ("Try again?") {
if (result=true) {
travel_function
} else {
msg ("You realize that you need to discover a new area to travel to first, before you can travel to that place.")
}
}
}
}
</function>
</asl>
feel free to try~test~play this code~"game" out (look at it in the GUI~Editor, if the code is still too hard for you to understand)
basicallly, you 'explore' (my 'explore' command-function), which randomly chooses an 'event' (a script), which adds that Room Object to your 'travel' list, which you can now move to, using my 'travel' command-function. Now, I got to remove those 'discovery events' (scripts), so they don't occur again, by removing them from the 'explore' list (which is the most complex part of my code, due to using random'ness method of seleting the events), and the 'travel' command-function is, I hope, self-explanatory.
I wrote this code a ways back, and I'm sure I could make it better (shorter code and a more clear~clean code), using script dictionaries, which I didn't realize at the time I did this code.
---------------
http://quest5.net/wiki/Using_Lists
http://quest5.net/wiki/Using_Dictionaries
--------------
http://quest5.net/wiki/Foreach
when you use the "foreach" function, it creates a variable that is set to the contents of the "foreach" string list or object list.
so the "o" (likely stands for "object", other common labels: obj, or my own structure of: adding a "_x" suffix, ie: object_x, item_x, result_x, value_x, and etc), is just that variable.
also, most people don't use "object" as their foreach iteration variable, as it may have conflict with the built-in "object" stuff, or it's just too confusing too, or they're just lazy, as writing "o" or "obj" or "i" (for "item") or "x", is faster, lol.
(object or string) list: soccer ball; football ball; baseball ball; basketball ball
foreach (object_x, global_data_object.sports_ball_object_list) {
-> object_x.play_with
}
conceptually:
for "soccer ball (object_x)", "play with (Verb)" the "soccer ball (object_x)"
for "football ball (object_x)", "play with (Verb)" the "football ball (object_x)"
for "baseball ball (object_x)", "play with (Verb)" the "baseball ball (object_x)"
for "basketball ball (object_x)", "play with (Verb)" the "basketball ball (object_x)"
here's a good example of concept of understanding the "foreach" list iteration function:
foreach (team_member_x, global_data_object.team_members_string_list) {
-> team_member_x.run_four_laps
}
// 'all=every=each' (for*EACH*) team member (team_member_x) of the 'team' (team_members_string_list), has to run 4 laps
---------
http://quest5.net/wiki/For
(lists start from 0, not 1)
(ordering is from left to right)
(soccerball;football;baseball;basketball)
list content 0 = soccerball
list content 1 = football
list content 2 = baseball
list content 3 = basketball
for (object_x, 1,1,1) {
-> object_x.play_with
}
// soccerball
for (object_x, 0,1,1) {
-> object_x.play_with
}
// soccerball and football
for (object_x, 0,2,1) {
-> object_x.play_with
}
// soccerball, football, and baseball
for (object_x, 0,2,2) {
-> object_x.play_with
}
// soccerball and baseball
for (object_x, 1,3,1) {
-> object_x.play_with
}
// football, baseball, and basketball
for (object_x, 1,3,2) {
-> object_x.play_with
}
// football and basketball
for (object_x, 0,3,4) {
-> object_x.play_with
}
// soccer and basketball
----------
by setting ("attaching") an Attribute to an Object, it enables the Attribute to be "permanent~global" ("save'able and load'able").
And, also, if you set the Attribute specifically to the "game" Game Object or to the "player" Player Object or "whatever" Player Object, then you can display those Attributes during game play, via the "status attributes" Attribute (which only works for the "game" Game Object, the "player" Player Object, and "whatever" Player Object).

Pertex
06 Feb 2014, 07:39Perhaps this can help: viewtopic.php?f=18&t=2817&hilit=car
davidw
06 Feb 2014, 12:49I thought Quest was aimed at non-programmers?

Pertex
06 Feb 2014, 15:05David, you are a member of this forum since 2003 and still do not know that complicated things have to be programmed by script?
davidw
06 Feb 2014, 15:26I thought the whole point of a GUI was to avoid the hassle of programming for the user.
(For what it's worth, I might have been a member of this forum for over a decade but I don't use Quest itself. I'm more of a casual lurker than anything.)
(For what it's worth, I might have been a member of this forum for over a decade but I don't use Quest itself. I'm more of a casual lurker than anything.)
ELGAROU
07 Feb 2014, 19:15I'm using the Travel function by HegemonKhan with some minor adaptions, also thanks for the syntaxis explanation.
greetings
greetings

jaynabonne
07 Feb 2014, 20:40In case anyone wants another take, attached is the beginning of some "taxi" code I wrote long ago (Quest 5.2!). When you run it, you can't click on the links in the room description for Forward and Reverse for some reason, but you can use the compass arrows.
This code also shows:
1) How to change the behavior of the compass,
2) How to run some code in real time (not something I would recommend, but you can do it),
3) How to have a moving room as a vehicle.
Note that the forward and reverse controls control speed (speed up, slow down, reverse, etc). It's meant to be on a track with speed, so there is no left or right, just speed up and slow down. To stop, slow down or type "stop". Each room to travel through has a "NextRoom" attribute that points to the next room in the sequence.
It might be too complex, but it's here if anyone wants it.
This code also shows:
1) How to change the behavior of the compass,
2) How to run some code in real time (not something I would recommend, but you can do it),
3) How to have a moving room as a vehicle.
Note that the forward and reverse controls control speed (speed up, slow down, reverse, etc). It's meant to be on a track with speed, so there is no left or right, just speed up and slow down. To stop, slow down or type "stop". Each room to travel through has a "NextRoom" attribute that points to the next room in the sequence.
It might be too complex, but it's here if anyone wants it.