Author Topic: [Solved] Counting number of elements in array  (Read 1345 times)

Shenron

  • Newbie
  • *
  • Posts: 16
[Solved] Counting number of elements in array
« on: June 06, 2022, 03:13:38 PM »
Hi there,

I'm playing with EliteVA plugin to Voice Attack.
EliteVA provide some game data into arrays like this :
Code: [Select]
{TXT:EliteAPI.Loadout.Modules[0].Slot}: ShipCockpit
{TXT:EliteAPI.Loadout.Modules[0].Item}: type9_military_cockpit
{BOOL:EliteAPI.Loadout.Modules[0].IsOn}: True
{INT:EliteAPI.Loadout.Modules[0].Priority}: 1
{DEC:EliteAPI.Loadout.Modules[0].Health}: 1
{TXT:EliteAPI.Loadout.Modules[1].Slot}: LargeHardpoint1
{TXT:EliteAPI.Loadout.Modules[1].Item}: hpt_pulselaserburst_turret_large
{BOOL:EliteAPI.Loadout.Modules[1].IsOn}: True
{INT:EliteAPI.Loadout.Modules[1].Priority}: 4
{DEC:EliteAPI.Loadout.Modules[1].Health}: 1
{TXT:EliteAPI.Loadout.Modules[2].Slot}: LargeHardpoint2
{TXT:EliteAPI.Loadout.Modules[2].Item}: hpt_pulselaserburst_turret_large
{BOOL:EliteAPI.Loadout.Modules[2].IsOn}: True
{INT:EliteAPI.Loadout.Modules[2].Priority}: 4
{DEC:EliteAPI.Loadout.Modules[2].Health}: 1
{TXT:EliteAPI.Loadout.Modules[3].Slot}: LargeHardpoint3
{TXT:EliteAPI.Loadout.Modules[3].Item}: hpt_pulselaserburst_turret_large
{BOOL:EliteAPI.Loadout.Modules[3].IsOn}: True
{INT:EliteAPI.Loadout.Modules[3].Priority}: 4
{DEC:EliteAPI.Loadout.Modules[3].Health}: 1
I wrote a test command to play with array but the loop break does not work.
The command always give me 50 elements found.
I attached a capture of the command and the VA output.

Can someone tell me where i'm wrong ?
« Last Edit: June 18, 2022, 11:08:17 AM by Shenron »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Counting number of elements in array
« Reply #1 on: June 06, 2022, 03:22:10 PM »
When tokens are used in the "Variable Name / Token" field, the comparison is performed against the literal text returned by those tokens, which cannot be null (the internal value/lack of value that is represented by VoiceAttack as "Not set") thus the "Has Been Set" or "Has Not Been Set" operators will always evaluate to true and false, respectively.

You'll need to compare against the literal text "Not set" (using the "Equals" operator) instead.
This does mean there is no method to differentiate between a text variable that has not been set, or one that has been set to the literal text "Not set".

Shenron

  • Newbie
  • *
  • Posts: 16
Re: Counting number of elements in array
« Reply #2 on: June 08, 2022, 06:03:42 AM »
Thank you Pfeil
I tried different approches but always the same issue so the only way to find the first element not in the array is the way you explain : compare with the "Not set" text

i also tried to retrieve other values like BOOL or INT but it's not working as expected
if have this command :
Code: [Select]
Set Boolean [~dockingComputer] to [{BOOL:EliteAPI.Loadout.Modules[{INT:~index}].IsOn}]Before this command :
  • ~dockingComputer is false
  • {BOOL:EliteAPI.Loadout.Modules[{INT:~index}].IsOn} is true
After this command, ~dockingComputer is not set
i don't understand where i'm wrong, i can't retrieve/copy the value

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Counting number of elements in array
« Reply #3 on: June 08, 2022, 08:52:47 AM »
Tokens are not variables, they return and are replaced by literal text (Variables and tokens summed up).

You are setting the value of "~dockingComputer", to the value of a variable named "True".


The "Variable Name / Token" field is an exception to the rule that most fields do take a mixture of literal text and tokens, without that changing the end result (I.E. including tokens in the "Another boolean variable value" field does not cause the input to be interpreted as literal text, but still as a variable name).

So, rather than retrieving the value of the variable using tokens, you'll want to only use the token that forms part of the variable name.

Shenron

  • Newbie
  • *
  • Posts: 16
Re: Counting number of elements in array
« Reply #4 on: June 08, 2022, 02:36:52 PM »
It's a bit disapointing
i have to dig more to better understand the limits of tokens and variable

checking the value this way
Code: [Select]
Begin Boolean Compare : [{EliteAPI.Loadout.Modules[{~index}].IsOn}] Equals Falseis also not working
is there a way to get verbose logs from voice attack ?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Counting number of elements in array
« Reply #5 on: June 08, 2022, 02:42:49 PM »
...now you're attempting to retrieve the value of a variable named "EliteAPI.Loadout.Modules[~index].IsOn" (as the token parser will remove curly braces that aren't part of a valid token), which would presumably be "Not set", as it won't exist.

I'll again recommend reading Variables and tokens summed up


If you want to check what the output of a given set of tokens will be, you can use the "Write a Value to the Event Log" action.

Shenron

  • Newbie
  • *
  • Posts: 16
Re: Counting number of elements in array
« Reply #6 on: June 08, 2022, 11:45:06 PM »
I'm also expecting the token is evaluated as Not set

thanks for the advice, i'll read your recommended article before any further question

Shenron

  • Newbie
  • *
  • Posts: 16
Re: Counting number of elements in array
« Reply #7 on: June 11, 2022, 02:22:16 AM »
Hi,

Just a big thanks for your help and your explanations about variables and tokens.
I managed to make my script working.