Get Object value through loop - Forum

Forum Navigation
You need to log in to create posts and topics.

Get Object value through loop

HI all

I have 3 objects MyT1, MyT2,MyT3 each of them have propertynames J1G,J2G,J3G,ScoreD,ScoreG. When I replace the digits by a variable I have a crash. I do not see a problem with the brackets, but perhaps this kind of syntax is not allowed ?

SetVar [Tour] 1

SetVar [FinLoop] 2

 

Loop 0 [FinLoop] [n]
Math "[MyT[Tour](n).ScoreG]-[MyT[Tour](n).ScoreD]" 0 [nEcart]    ==>Uncaught SyntaxError: missing ] in index expression
Loop 1 3 [n2]

SetVar [nJ] [MyT[Tour](n).J[n2]G]

or
SetVar [nJ] [MyT1(n).J[n2]G]  ==> Uncaught SyntaxError: missing ] in index expression
EndLoop
EndLoop

Hi @phil78 you can't use nested brackets, except if you use SetCompVar and GetCompVar.
Regards.

Thanks @Luishp, I don't know why I thought it was reserved for arrays !!!

best regards

finally I see that GetCompVar is not able to read the value of my variable.
No crash but the variable is still undefined :

GetCompVar [sg] [MyT[Tour]([n]).ScoreG]

Hi @phil78 I think that expression is too complex for GetCompVar. It expects the same usage as NeoBook or VisualNEO Win users are used to. In VisualNEO Win this trick is used to mimic Arrays as there are not real Arrays there.
In your case I think it's probably better to use Arrays of objects (like when parsing data from a database) or multidimensional Arrays.

I hope it helps.

Regards.

@phil78

I have 3 objects MyT1, MyT2,MyT3 each of them have propertynames J1G,J2G,J3G,ScoreD,ScoreG

According to the Help file for the command GetCompVar ...

Get the value from a composed variable (see SetCompVar) and assign it to a regular one.

GetCompVar [result] [var1[var2]]
var1 is First fixed part of the composed variable.
var2 is Second mutable part of the composed variable.

So, instead of ...

GetCompVar [sg] [MyT[Tour]([n]).ScoreG]

... try doing it in multiple steps ...

1) GetCompVar [temp1] [MyT[Tour]]
... [temp1] will then be MyT1, MyT2, MyT3 depending on current value of [Tour]

2) I am not sure what [n] is supposed to be; are MyT1 (MyT2, MyT3) supposed to be arrays, where each array item has properties like ScoreG ?

3) Assuming that there are no array elements, just properties for each object ...

SetVar [sg] [temp1.ScoreG]

[sg] will contain the value assigned to property ScoreG of [temp1]

luishp has reacted to this post.
luishp

Hi @gaev , Your solution is good thank you. (thanks also to @luishp).

GetCompVar [tempo] [MyT[Tour]]
SetVar [sc] [tempo([n]).ScoreG]   (n is the index of my object MyT1)

luishp has reacted to this post.
luishp