[help] log10(...) and table count

The place to discuss scripting and game modifications for X4: Foundations.

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

Eagle_Four
Posts: 231
Joined: Wed, 6. Nov 02, 20:31
x3

[help] log10(...) and table count

Post by Eagle_Four » Sat, 29. Jul 23, 17:39

Hello,

1.I need the number of entries in a table. i tried .count but it only works for a list.
But I want to empty a table from a certain number so that my save doesn't get bigger and bigger. (And for other checks using loop).

This works for a list but not for a table:

Code: Select all

<debug_text text="'List (count): ' + $testlist.count" chance="$debugChance"/>
This does not work for a table:

Code: Select all

<debug_text text="'Table (count): ' + $table.count" chance="$debugChance"/>
2. For a calculation I need the log10(...) function.
But I found only sqrt(2) in the X4 docu.

How can I calculate log10(...) in X4 without having to access an external Lua script?
Which is possible, but I wanted to limit the dependencies to vanilla since it's just a small mod project.

Thanks a lot in advance.

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13308
Joined: Sun, 15. Feb 04, 20:12
x4

Re: [help] log10(...) and table count

Post by euclid » Sat, 29. Jul 23, 18:14

For tables use .key rather than .count. The log10 is tricky as there is no such math function available in xml. If you do not wish to use lua then you could write a subcue or lib that counts the number of division by 10 until the result is 1.

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

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [help] log10(...) and table count

Post by kuertee » Sun, 30. Jul 23, 12:24

Eagle_Four wrote:
Sat, 29. Jul 23, 17:39
Hello,

1.I need the number of entries in a table. i tried .count but it only works for a list.
...
Thanks a lot in advance.
there are some nifty table functions:
$table.keys is a list, so you can do $table.keys.count.
you can also iterate through the keys and values directly:

Code: Select all

<do_for_each name="$key" valuename="$value" in="$table">
	<debug_text text="'$key: ' + $key + " $value: ' + $value" />
</do_for_each>
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

jan12342203
Posts: 65
Joined: Sat, 14. May 16, 22:13
x4

Re: [help] log10(...) and table count

Post by jan12342203 » Sun, 30. Jul 23, 12:34

whats the difference of log and log10?
because log is available but not log10?

jan12342203
Posts: 65
Joined: Sat, 14. May 16, 22:13
x4

Re: [help] log10(...) and table count

Post by jan12342203 » Sun, 30. Jul 23, 12:37

from the scriptproperties.html just for reference whats avail.. for table

Code: Select all

table
Properties:
clone	        table	        A shallow copy of the table
keys.count	integer	        Number of keys in the table
keys.list       list            List of all keys in the table (reliably sorted if all keys are numeric, otherwise order can change between savegames)
keys.sorted	list            List of all keys in the table, sorted by their associated values (requires all values to be numeric)
keys.random		        A random key in the table (the table must be non-empty)
keys.{$numeric}		        The $numeric-th key in the table (1-based), note that this lookup can be inefficient and order can change between savegames
{$key}		                Value associated with the table key (type is ignored for numeric keys, e.g. 50s and 50m are treated as the same key)
$<keyname>		        Value associated with the table key (shortcut for {'$<keyname>'}, all string keys must begin with '$')

User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 24969
Joined: Sun, 2. Apr 06, 16:38
x4

Re: [help] log10(...) and table count

Post by X2-Illuminatus » Sun, 30. Jul 23, 14:18

jan12342203 wrote:
Sun, 30. Jul 23, 12:34
whats the difference of log and log10?
because log is available but not log10?
log = logarithm to the base of the mathematical constant e (i.e. the Euler's number), this is often also described as natural logarithm (ln).
log10 = logarithm to the base of 10.
Nun verfügbar! X3: Farnham's Legacy - Ein neues Kapitel für einen alten Favoriten

Die komplette X-Roman-Reihe jetzt als Kindle E-Books! (Farnhams Legende, Nopileos, X3: Yoshiko, X3: Hüter der Tore, X3: Wächter der Erde)

Neuauflage der fünf X-Romane als Taschenbuch

The official X-novels Farnham's Legend, Nopileos, X3: Yoshiko as Kindle e-books!

jan12342203
Posts: 65
Joined: Sat, 14. May 16, 22:13
x4

Re: [help] log10(...) and table count

Post by jan12342203 » Sun, 30. Jul 23, 15:09

thanks for clarifying this :-)

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13308
Joined: Sun, 15. Feb 04, 20:12
x4

Re: [help] log10(...) and table count

Post by euclid » Sun, 30. Jul 23, 18:51

jan12342203 wrote:
Sun, 30. Jul 23, 12:34
.....
because log is available but not log10?
If the available log is indeed the natural logarithm ln (see X2-Illuminatus post), then you could use log10(x):= log(x)/log(10) which may be faster than what I've suggested above. ;-)

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

jan12342203
Posts: 65
Joined: Sat, 14. May 16, 22:13
x4

Re: [help] log10(...) and table count

Post by jan12342203 » Sun, 30. Jul 23, 19:07

xD.. Indeed haha

Eagle_Four
Posts: 231
Joined: Wed, 6. Nov 02, 20:31
x3

Re: [help] log10(...) and table count

Post by Eagle_Four » Mon, 31. Jul 23, 19:43

kuertee wrote:
Sun, 30. Jul 23, 12:24

there are some nifty table functions:
$table.keys is a list, so you can do $table.keys.count.
you can also iterate through the keys and values directly:

Code: Select all

<do_for_each name="$key" valuename="$value" in="$table">
	<debug_text text="'$key: ' + $key + " $value: ' + $value" />
</do_for_each>
Thank you very much, works perfectly.
jan12342203 wrote:
Sun, 30. Jul 23, 12:37
from the scriptproperties.html just for reference whats avail.. for table

Code: Select all

table
Properties:
clone	        table	        A shallow copy of the table
keys.count	integer	        Number of keys in the table
keys.list       list            List of all keys in the table (reliably sorted if all keys are numeric, otherwise order can change between savegames)
keys.sorted	list            List of all keys in the table, sorted by their associated values (requires all values to be numeric)
keys.random		        A random key in the table (the table must be non-empty)
keys.{$numeric}		        The $numeric-th key in the table (1-based), note that this lookup can be inefficient and order can change between savegames
{$key}		                Value associated with the table key (type is ignored for numeric keys, e.g. 50s and 50m are treated as the same key)
$<keyname>		        Value associated with the table key (shortcut for {'$<keyname>'}, all string keys must begin with '$')
This is exactly what I was looking for. Thank you very much.
euclid wrote:
Sun, 30. Jul 23, 18:51
jan12342203 wrote:
Sun, 30. Jul 23, 12:34
.....
because log is available but not log10?
If the available log is indeed the natural logarithm ln (see X2-Illuminatus post), then you could use log10(x):= log(x)/log(10) which may be faster than what I've suggested above. ;-)

Cheers Euclid
Works, I have just tested. I also did not know that log (x) works in X4. In the MD XRebirth doku the function is not described. I had now but already a LUA script ready, but this method is better, I have to wait with Lua first a tic for the result, which is sometimes not so optimal under certain circumstances.

Return to “X4: Foundations - Scripts and Modding”