Questions about group and list

The place to discuss scripting and game modifications for X Rebirth.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

Phipsz
Posts: 335
Joined: Mon, 23. Apr 12, 23:56
x4

Post by Phipsz »

J3ANP3T3R wrote:i still don't understand the table thing and im a programmer in real life working with tables. one with rows and columns.
this table is based on the lua datatype named table, which is actually a combination of lists and "mappings" (I would call them that). I don't know which programming languages you know, but equivalents would be "dict" in python, HashMap in C++/Java or basic arrays in php. it's basically the same as list, but instead of only integers you can use strings as key as well, or even objects like player.primaryship.

as for my previous example, yes i meant ' exact=" ', the ' exact"= ' was a typo. you could iterate through this list of tables like

Code: Select all

<do_all exact="$details.count" counter="$i">
  <set_value name="$current_entities" exact="$details.{$i}.$entities" />
  <set_value name="$current_zones" exact="$details.{$i}.$zones" />
</do_all>
where $current_entities and $current_zones would be the lists you assigned before. in tables you could assign null-values as well, but not as key, as with lists how UniTrader already pointed out :)
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

sad ... it would be really helpful if we can automatically remove all reservations for an entity to eliminate hanging reservations.

how does get_trade_from_shoppinglist get the planned trade routes ?
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

erm.. thats what the reservation Timeout (@duration) is for :roll: ;) the attribute is not required, but if not specified it defaults to 1 hour - and you can extend it as needed if your trip takes longer as planned..

the Trade Shoppiglist is filled either by the Player or by the Script running on i think the ship entity
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

UniTrader wrote:erm.. thats what the reservation Timeout (@duration) is for :roll: ;) the attribute is not required, but if not specified it defaults to 1 hour - and you can extend it as needed if your trip takes longer as planned..

the Trade Shoppiglist is filled either by the Player or by the Script running on i think the ship entity
ah i see... not gonna work on me because im using my own trade script. and they just use add_ware reservations. time is good but it would be better if you can remove all reservations at will or when a trade failed.
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

Phipsz wrote: this table is based on the lua datatype named table, which is actually a combination of lists and "mappings" (I would call them that). I don't know which programming languages you know, but equivalents would be "dict" in python, HashMap in C++/Java or basic arrays in php. it's basically the same as list, but instead of only integers you can use strings as key as well, or even objects like player.primaryship.

as for my previous example, yes i meant ' exact=" ', the ' exact"= ' was a typo. you could iterate through this list of tables like

Code: Select all

<do_all exact="$details.count" counter="$i">
  <set_value name="$current_entities" exact="$details.{$i}.$entities" />
  <set_value name="$current_zones" exact="$details.{$i}.$zones" />
</do_all>
where $current_entities and $current_zones would be the lists you assigned before. in tables you could assign null-values as well, but not as key, as with lists how UniTrader already pointed out :)
thanks... i will look into the table property when i have the time. it could be useful. i use Visual Foxpro 9.0 best language when handling databases. we shifted from dbf to mysql. im used to those types of tables. does x-rebirth table have columns and rows as well ?
User avatar
wysiwyg
Posts: 585
Joined: Thu, 26. Feb 04, 00:08
x4

Post by wysiwyg »

J3ANP3T3R wrote:thanks... i will look into the table property when i have the time. it could be useful. i use Visual Foxpro 9.0 best language when handling databases. we shifted from dbf to mysql. im used to those types of tables. does x-rebirth table have columns and rows as well ?
In most programming languages rows and columns are not explicitly supported but multi-dimensional arrays generally are; which does give you the tools to "make" your own representation of rows and columns as long as you maintain your convention to avoid bugs e.g.

(Pseudo code)

Code: Select all

$RCtable=[ 
$row_1 = [element1, element2, ......, element_n] ,
$row_2 = [element1, element2, ......, element_n] ,
$row_n = [element1, element2, ......, element_n] ,
]
so the table can be indexed as $RCtable.$row_2.{2} to access the value at row 2 column 2
As Phipsz said you could easily omit the '$row_n =' part and have a pure indexed RC table accessed as:

Code: Select all

$RCtable=[ 
[element1, element2, ......, element_n] ,
[element1, element2, ......, element_n] ,
[element1, element2, ......, element_n] ,
]
So our row2, column2 value is accessed now by $RCtable.{2}.{2}
EDIT: Just as a general observation on tables and lists: List are good if you need to iterate over the whole list but tables are good if you need to extract a specific value without having to iterate over the whole list to look for it. In MD/AI script there is a facility to iterate over a key/value pair table using the 'keys' and 'keys.count' properties of the table.
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

wysiwyg wrote:
J3ANP3T3R wrote:thanks... i will look into the table property when i have the time. it could be useful. i use Visual Foxpro 9.0 best language when handling databases. we shifted from dbf to mysql. im used to those types of tables. does x-rebirth table have columns and rows as well ?
In most programming languages rows and columns are not explicitly supported but multi-dimensional arrays generally are; which does give you the tools to "make" your own representation of rows and columns as long as you maintain your convention to avoid bugs e.g.

(Pseudo code)

Code: Select all

$RCtable=[ 
$row_1 = [element1, element2, ......, element_n] ,
$row_2 = [element1, element2, ......, element_n] ,
$row_n = [element1, element2, ......, element_n] ,
]
so the table can be indexed as $RCtable.$row_2.{2} to access the value at row 2 column 2
As Phipsz said you could easily omit the '$row_n =' part and have a pure indexed RC table accessed as:

Code: Select all

$RCtable=[ 
[element1, element2, ......, element_n] ,
[element1, element2, ......, element_n] ,
[element1, element2, ......, element_n] ,
]
So our row2, column2 value is accessed now by $RCtable.{2}.{2}
EDIT: Just as a general observation on tables and lists: List are good if you need to iterate over the whole list but tables are good if you need to extract a specific value without having to iterate over the whole list to look for it. In MD/AI script there is a facility to iterate over a key/value pair table using the 'keys' and 'keys.count' properties of the table.
thanks ! because of this i now have a better understanding of what the tables are for. it does look nothing different from a regular list except we can now pull up data from the table without having to go through the entire list. actually in the list we can use an index as well so as not to have to loop through the entire list but table is better if we dont expect to know the specific index but only the variable.

i basically confused it with an actual database table. it looks like a collection of variables or a list within a list but with better retrieval. thanks.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

J3ANP3T3R wrote:
UniTrader wrote:erm.. thats what the reservation Timeout (@duration) is for :roll: ;) the attribute is not required, but if not specified it defaults to 1 hour - and you can extend it as needed if your trip takes longer as planned..

the Trade Shoppiglist is filled either by the Player or by the Script running on i think the ship entity
ah i see... not gonna work on me because im using my own trade script. and they just use add_ware reservations. time is good but it would be better if you can remove all reservations at will or when a trade failed.
well, you have a timeout anyway (the mentoined 1 hour if not specified) - if your ship takes longer that could be the reason why the trade failed: your reservation expired and the trade you wanted is no longer available.. logically a reserved trade should be possible as long as it is reserved

also if you write your own trade script you should already keep track of the trades you want to do.. (i would use the shoppinglist for that btw - makes most sense) and if your script gets aborted for some reason you can clean up with the <on_abort/>-node (silbling of<attention/> )
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

UniTrader wrote: well, you have a timeout anyway (the mentoined 1 hour if not specified) - if your ship takes longer that could be the reason why the trade failed: your reservation expired and the trade you wanted is no longer available.. logically a reserved trade should be possible as long as it is reserved

also if you write your own trade script you should already keep track of the trades you want to do.. (i would use the shoppinglist for that btw - makes most sense) and if your script gets aborted for some reason you can clean up with the <on_abort/>-node (silbling of<attention/> )
oh no that was just a sample. my point about the whole reservation thing is to use it for safety. to really be sure that this ship will have no reservations left after a trade success or fail i wanted to remove all of its reservations. my ships are trading fine except for neutonian v crushers :shock: damn missiles.

yep i have abort scripts for that just like in the vanilla scripts. but they can only remove trade reservations for the current "buyoffers" or "selloffers" that were passed on to the script ... im using a script that handles multiple trade missions like the vanilla mining scripts so i wanted to make a safety code just in case.

ill review get_trade_from_shoppinglist i think you are right about this one its just that i dont know how the trades are added to the shoppinglist so i dont know if my trade script is adding trades to it or i may be missing something from the vanilla. is it during on add_ware_reservations that they are added to the ships shoppinglist ? i havent got a clue :idea:
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

since basically everything we know about tables is already said in this thread i will dig it out for some further questions:

basically it is about how can i work with already existing thables in AI/MD-Script?
=> how to modify Values? (i think <set_value/> works in this case as expected)
===> how to add a new key to an existing table? i guess <append_to_list/> could work for this since i havent found an equivalent for tables, like
<add_to_table name="$table" key="$key" exact="$value"/>
=> and how to remove Keys/values from tables? (i think <remove_value/> should work as expected in this case)


EDIT: forget this question - its answer is here on Page 1 - i just was too tired when looking this up to see it..
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

Return to “X Rebirth - Scripts and Modding”