Array duplicate - 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: Array duplicate (
/showthread.php?tid=664769)
Array duplicate -
Johurt - 10.03.2019
Hello, I want to write the code that will duplicate the array. Mine code works, but whether there are no bugs?
Код:
enum pItem
{
hi,
bye,
abc[10]
}
new pInfo[2][pItem];
main()
{
pInfo[0][hi] = 7;
pInfo[0][bye] = 44;
format(pInfo[0][abc], 5, "text");
for(new i; pItem:i < pItem; i++) pInfo[1][pItem:i] = pInfo[0][pItem:i];
printf("hi: %d | bye: %d | abc: %s", pInfo[1][hi], pInfo[1][bye], pInfo[1][abc]);
}
Re: Array duplicate -
Kaliber - 11.03.2019
Yes, you could do it like this.
But you can also set it directly, which would be much faster:
PHP код:
main()
{
pInfo[0][hi] = 7;
pInfo[0][bye] = 44;
format(pInfo[0][abc], 5, "text");
pInfo[1] = pInfo[0];
printf("hi: %d | bye: %d | abc: %s", pInfo[1][hi], pInfo[1][bye], pInfo[1][abc]);
}
Re: Array duplicate -
Johurt - 11.03.2019
I didn't know that my variant with preset values doesn't work.
Код:
enum pItem {
hi = 3,
bye = 2
}
new pInfo[2][pItem];
Quote:
Originally Posted by ******
There's also a memcpy function already.
|
This is correct code?
Код:
new size = sizeof(pInfo[]);
memcpy(pInfo[1], pInfo[0], 0, size * 4, size);
Quote:
Originally Posted by Kaliber
Yes, you could do it like this.
But you can also set it directly, which would be much faster:
PHP код:
main()
{
pInfo[0][hi] = 7;
pInfo[0][bye] = 44;
format(pInfo[0][abc], 5, "text");
pInfo[1] = pInfo[0];
printf("hi: %d | bye: %d | abc: %s", pInfo[1][hi], pInfo[1][bye], pInfo[1][abc]);
}
|
Thank you guys.
Re: Array duplicate -
Johurt - 11.03.2019
Quote:
Originally Posted by ******
I believe so.
|
Thank you.