Page 1 of 1

EOS question. Using the SAY action with Objects

Posted: Wed Mar 02, 2022 3:47 am
by Lamei
I'm having trouble getting the SAY action to display whole or part of an object. I understand how to use the SAY action with arrays, but no matter what I try, I can't get it to work with objects. For example:

const testA = [ {Name : Player 0, Score : 12, Rank : 1},
{Name : Player 1, Score : 8, Rank : 3},
{Name : Player 2, Score : 9, Rank : 2},
]

My question is how would I use the SAY command to display Player 0s Rank? Can the whole object 'testA' be shown at once?

Re: EOS question. Using the SAY action with Objects

Posted: Wed Mar 02, 2022 6:54 am
by grelgen
the first thing I see, surround your name data with quotes:
const testA = [
{Name : "Player 0", Score : 12, Rank : 1},
{Name : "Player 1", Score : 8, Rank : 3},
{Name : "Player 2", Score : 9, Rank : 2},
];

test after that, it all might start working

at any time, you can
console.log(testA);
to see the contents

Re: EOS question. Using the SAY action with Objects

Posted: Wed Mar 02, 2022 10:05 am
by Lamei
Thanks Grelgen. My mistake, I forgot the quotation marks around the names haha. I fixed that but unfortunatly I can't get it working. I'm probably trying to use the SAY action wrong. If I was using an array I would simply use the SAY action like this:

var Players = ["player1","player2","player3]

(using SAY action eval tag) Players[0] will say player1


But when i'm using the SAY action for an object like this it's not working:

const Player = {name : "Player1", score : 5, rank : 3}

(using SAY action eval tag) Player.rank will not work when I expect it to say 3


Anyway thanks for your time.

Re: EOS question. Using the SAY action with Objects

Posted: Wed Mar 02, 2022 11:12 am
by Thamrill
I was sure I had answered this question, anyhow, try defining the array as a var rather than a const. That way should work (worked for me).
Also, I tried to pass the array of objects to the say action and it doesn't work, it prints [Object object, Object object, Object object]

Re: EOS question. Using the SAY action with Objects

Posted: Wed Mar 02, 2022 9:52 pm
by Lamei
Thamrill wrote: Wed Mar 02, 2022 11:12 am I was sure I had answered this question, anyhow, try defining the array as a var rather than a const. That way should work (worked for me).
Also, I tried to pass the array of objects to the say action and it doesn't work, it prints [Object object, Object object, Object object]
Thanks very much Thamrill, it works! I wish I had asked sooner as I admit I spent a couple of hours trying everything and wondering why I couldn't get it to work. Thank you