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

J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Questions about group and list

Post by J3ANP3T3R »

Hey guys. i have done a lot of asking around and i apologize for the threads. i will try and merge all my question threads into one thread as soon as they are answered.

may i ask what is the difference between group and list and why group cannot have a "count" property ?
User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13486
Joined: Sun, 15. Feb 04, 20:12
x4

Post by euclid »

Hi J3ANP3T3R :-)

Think of groups and lists In terms of sets then the list is an ordered set. So you can add or remove members of a group but since there is no order you cannot have a counter as for lists.

Hope that helps.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

huh? groups do have a count attribute... at least according to scriptproperties.html the last timee i checked.. (today morning)
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 »

euclid wrote:Hi J3ANP3T3R :-)

Think of groups and lists In terms of sets then the list is an ordered set. So you can add or remove members of a group but since there is no order you cannot have a counter as for lists.

Hope that helps.

Cheers Euclid
thanks ! that explains the differences and why there had to be a group and a list. although unitrader was right i was looking at a backup copy of scriptproperties and in 3.5 groups have the count property.
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

UniTrader wrote:huh? groups do have a count attribute... at least according to scriptproperties.html the last timee i checked.. (today morning)
thanks i did check and in 3.5 there actually is a count property for groups. i was looking at the wrong scriptproperties.
Xenon_Slayer
EGOSOFT
EGOSOFT
Posts: 13126
Joined: Sat, 9. Nov 02, 11:45
x4

Post by Xenon_Slayer »

The groups are specifically for use by objects. When you have the objects in the group they:
- can be used in event_ conditions via the group="" attribute
- will automatically be removed when destroyed
- can not be added to a group multiple times

With lists, you can store any type of value.
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

thanks ! that added clarity. may i additionally ask, how can i create a list containing 2 more lists on each index ?

for example ...

create list $entities contains 10 NPCs
create list $zones contains 10 ZONES

i want to put them on a single list say $details

so that i can do_all $details like

do_all $details.count counter $d
$details.{$d}.$entities.{2}
$details.{$d}.$zones.{2}

something like that.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

Code: Select all

<set_value name="$details" exact="
[
[ $entity1 , $zone1 ] ,
[ $entity2 , $zone2 ] ,
……………
[ $entityN , $zoneN ]
]" />
(multi-line for clarity)

or if you want to create it from existing lists or by iteration through something else:

Code: Select all

<create_list name="$details" />
<do_all exact="$entities.count" counter="$i>
  <append to list name="$details" exact="[ $entities.{$i} , $zones.{$i} />
</do_all>
you access these by $details.{$x}.{1|2}

and after posting this i noticed yu meant something a bit diffrent.. but wont remove it now..

EDIT:
the way you want it to be done would require that $details.{$i} resolves to something which can store Values, for example an Entity (you would access its blackboard then) or an MD Cue (remote Var Accesss; MD only) - both have their obvious problems (requires entity or cue of its own)
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 ;)
Phipsz
Posts: 335
Joined: Mon, 23. Apr 12, 23:56
x4

Post by Phipsz »

UniTrader wrote: EDIT:
the way you want it to be done would require that $details.{$i} resolves to something which can store Values, for example an Entity (you would access its blackboard then) or an MD Cue (remote Var Accesss; MD only) - both have their obvious problems (requires entity or cue of its own)
Also, there is the datatype "table" ego has introduced in 3.50RC3:
changelog wrote: New script datatype "table" mapping arbitrary keys to values

You can assign values to arbitrary keys, e.g. to $table.{1} or $table.{player.primaryship}
You can assign values to variable-type keys, e.g. to $table.$foo (shortcut for $table.{'$foo'})
Almost all values are allowed as table keys - exceptions:
- Strings must start with '$' (bad: $table.foo, good: $table.$foo)
- Lists, tables, groups and buildplans cannot be used as table keys
- null cannot be used as table key (but the number 0 is valid)
Example syntax for creating and initialising a table:
- "table[]" (empty table)
- "table[$foo = 42]" (a table that maps string '$foo' to 42)
- "table[$bar = $bar, {10} = []]" (mapping '$bar' to the value of the variable $bar, and the number 10 to an empty list)
- "table[{$baz} = null]" (mapping the value of $baz to null)
Use <set_value> and <remove_value> to add/remove table entries, and "?" to check for existence of a key
See scriptproperties documentation for available table properties
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

ah, didnt know about this one - thx for the hint :)
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 ;)
Phipsz
Posts: 335
Joined: Mon, 23. Apr 12, 23:56
x4

Post by Phipsz »

yeah, found it by accident when working with ui-stuff and return-values from lua to md. everything worked fine until 3.50rc3, but suddenly I got this new table-datatype instead of a list (which I expected of course) and everything broke... but it's nice to have this datatype now :)

@J3ANP3T3R: I guess now it would be something like this

Code: Select all

<set_value name="$details" exact"=
[
  table[
    $entities = [ ... ],
    $zones = [ ... ]
  ],
  ...
]" />
although I suspect that UniTraders solution is what you were really seeking
User avatar
wysiwyg
Posts: 585
Joined: Thu, 26. Feb 04, 00:08
x4

Post by wysiwyg »

Yes the new table types are really handy as you can now pass hashed tables between Lua and MD instead of having to index long lists each time.
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

Phipsz wrote:yeah, found it by accident when working with ui-stuff and return-values from lua to md. everything worked fine until 3.50rc3, but suddenly I got this new table-datatype instead of a list (which I expected of course) and everything broke... but it's nice to have this datatype now :)

@J3ANP3T3R: I guess now it would be something like this

Code: Select all

<set_value name="$details" exact"=
[
  table[
    $entities = [ ... ],
    $zones = [ ... ]
  ],
  ...
]" />

although I suspect that UniTraders solution is what you were really seeking

Thank you all guys. i think the table would do if the normal list on a list will not work. what i actually wanted to do is add the two lists as properties of a main list. each member of the list $details will each have two property $entities and $zones both of which are also lists.

if i use your example

<set_value name="$details" exact"=
[
table[
$entities = [ ... ],
$zones = [ ... ]
],
...
]" />

how do i access each property ? is there really an = after 'exact" ' ? what does = mean ? i think unitrader's list within a list could also work it makes sense. thank you :D
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

Guys if a list say $Masterlist have 3 counts and i add a member $NPCFound which is null ... will the list accept a member with a null value and make it 4 members now ?
User avatar
wysiwyg
Posts: 585
Joined: Thu, 26. Feb 04, 00:08
x4

Post by wysiwyg »

J3ANP3T3R wrote:Thank you all guys. i think the table would do if the normal list on a list will not work. what i actually wanted to do is add the two lists as properties of a main list. each member of the list $details will each have two property $entities and $zones both of which are also lists.

how do i access each property ? is there really an = after 'exact" ' ? what does = mean ? i think unitrader's list within a list could also work it makes sense. thank you :D
In general a list is index based just like an array in C/C++ so:

Code: Select all

<set_value name="$a" exact="1"/>
<set_value name="$b" exact="20"/>
<set_value name="$c" exact="300"/>
<set_value name=$myList exact=[$a, $b, $c]/>

$myList.{1}   is value 1
$myList.{2}   is value 20
$myList.{3}   is value 300
Tables are hash based i.e. they are key/value pair entries just like tables in Lua so:

Code: Select all

<set_value name="$myTable" exact="[ $keya=$a, $keyb=$b, $keyc=$c] />
now I can access these as properties:

$myTable.$keya  is value 1
$myTable.$keyb  is value 20
$myTable.$keyc  is value 300
exact = 1 is an assignment just like in C.

<set_value name="$myVariable" exact="12.07"/>
is equivalent to something like:
float myVariable = 12.07;
in C.

Edit: Just seen your last post - I don't think you can have NULL as a key but it should be fine as a value.
User avatar
YorrickVander
Posts: 2774
Joined: Tue, 29. Oct 13, 21:59
x4

Post by YorrickVander »

I could only find a data type entry then this in common.xsd, so I assume the mechanism is more designed for passing tables from lua than for creating them in xml.

Code: Select all

      <xs:element name="clear_table">
        <xs:annotation>
          <xs:documentation>
            Clear a table, i.e. remove all keys and values from it
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:attributeGroup ref="action" />
          <xs:attribute name="table" type="table" use="required" />
        </xs:complexType>
      </xs:element>
I would infer from this that we access the data as if it was a list of lists in the same way as it's done in the md for npc wares + prices data.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

ah so in '<set_value name="$details" exact"= ' its <set_value name="$details" exact=" ?

also about the null thing ... the list wont accept it ? darn i was hoping i can have for example

$list.{1} = 'a'
$list.{2} = 'b'
$list.{3} = null
$list.{4} = 'c'

to synchronize data from another list and they both had to use the same index.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

list.{3} = null does work ;) (or appending a null value to a list) what does not work is list.{null} = 3 obviously

similiar for tables - null does not work as key name (no idea how you could even write that) - but it would work as resulting value ;)
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:list.{3} = null does work ;) (or appending a null value to a list) what does not work is list.{null} = 3 obviously

similiar for tables - null does not work as key name (no idea how you could even write that) - but it would work as resulting value ;)
Thanks ! i was hoping it would work because i still don't understand the table thing and im a programmer in real life working with tables. one with rows and columns.

if i may... i would like to insert another question without spamming a new thread. is there a way for me to remove ware reservations from an entity without specifying the object and the ware ?

for example

<remove_ware_reservation entity="this" />

will this work ?

what about getting the ware reservations of an entity

<get_ware_reservation entity="this" />


thanks :D
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

for both (get and remove) nope, object is required according to doc.
but you can iterate through the Shoppinglist ( <get_trade_from_shoppinglist /> to see which Stations a Ship/entity plans to trade with ;)
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”