SA-MP Forums Archive
Directly add values to a 2 dimensional array ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Directly add values to a 2 dimensional array ? (/showthread.php?tid=415445)



Directly add values to a 2 dimensional array ? - denNorske - 13.02.2013

Why will this work:
pawn Код:
new plantgrammy;
        plantgrammy = drugs[playerid][plantgrams] +5;
        drugs[playerid][plantgrams] = plantgrammy;
        dini_IntSet(connect, "plantgrams", drugs[playerid][plantgrams]);
And this not?

pawn Код:
drugs[playerid][plantgrams] + 5;
Thanks for any explanation


Re: Directly add values to a 2 dimensional array ? - LarzI - 13.02.2013

The last piece of code doesn't assign anything. It's just an expression. You'll need to use += for your purpose
pawn Код:
drugs[ playerid ][ plantgrams ] += 5;



Re: Directly add values to a 2 dimensional array ? - denNorske - 13.02.2013

Quote:
Originally Posted by LarzI
Посмотреть сообщение
The last piece of code doesn't assign anything. It's just an expression. You'll need to use += for your purpose
pawn Код:
drugs[ playerid ][ plantgrams ] += 5;
Thanks LarzI You know, i was just trying to play around with arrays, and i found out that it didn't compile, and i found out that arrays does not work like variables

@******:

I was not sure either about what it would do, as it didn't compile. I was just trying to add 5 into the value it was holding. So, i suppose that LarzI's Comment was correct, and that it works somehow better now


Thanks anyways! ^^