Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Krillan87 on December 18, 2017, 06:24:22 AM

Title: Can't add int to an array.
Post by: Krillan87 on December 18, 2017, 06:24:22 AM
Hi,

So I have this multiplayer arena game. When 1 player dies he sends a RPC call to a scoreboard with the killer's name.

In the scoreboard there is an array with all the players names and one array with the current score of the players.

1. First the manager checks if the name exists in the array and store the index.
2. Then we check the score array for the same index and store the current score.
3. we add 1 to that score
4. we set the array again with the new score.

Pretty straight forward. However, It only works the first time.

When 1 player dies the scene restarts and there is a "don't destroy on load" on the scoreboard. So it stays untouched through the restart.

The problem here is that the "int add" does nothing in the second round.

Clarifications:
The player names are "Ond Kille 86" and "Krillan".
Krillan already has 1 point and the picture is after the second kill, showing that the array do not go up by one.

It feels like there is a simple error somewhere but maybe I'm to tired to get what is wrong here. This is the first time I worked with arrays so that's why I'm a bit unsure.

Any inputs?


Title: Re: Can't add int to an array.
Post by: ... on December 18, 2017, 07:17:19 AM
Just one question, why don't you use the hash table? It would be much simpler, and you only need one table, not two arrays.

PlayerScore
Player 1250
Player 21000
Title: Re: Can't add int to an array.
Post by: Krillan87 on December 19, 2017, 05:19:03 AM
Just one question, why don't you use the hash table? It would be much simpler, and you only need one table, not two arrays.

PlayerScore
Player 1250
Player 21000

Hi!

I got this from a tutorial online and it's the first time using it.

I have never heard of hashtables so I guess that's why haha. I'm such a newbie to arrays so this in uncharted waters for me.

What is hashtables? Are they easier to use?

I'm goona google hashtables and check them out. Thanks!
Title: Re: Can't add int to an array.
Post by: Krillan87 on December 19, 2017, 06:37:04 AM
Just one question, why don't you use the hash table? It would be much simpler, and you only need one table, not two arrays.

PlayerScore
Player 1250
Player 21000

Okey, some googling later... I have a basic question that I do not manage to get quick answers for:

Is the "only" big difference between hash tables and arrays that in hashtable you use a key (string) instead of an index number? So you can use the key-name as  information as well.

Or how exact does them differ?

Title: Re: Can't add int to an array.
Post by: ... on December 19, 2017, 08:13:12 AM
Yes, you can also use a key as an information. Hash tables use arrays actually. With regular arrays, if you don't know the index of an item you are looking for, you have to iterate through the whole array. With hash tables, you only need the key - faster and easier for extraction and insertion.