SA-MP Forums Archive
sizeof operator not functioning - 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: sizeof operator not functioning (/showthread.php?tid=653118)



sizeof operator not functioning - iSpark - 26.04.2018

So I'm not sure why but the sizeof operator is throwing an error when the parameter is a string residing in an enumarator.

Код:
format(tpInfo[tpID][tpName], sizeof(tpInfo[tpID][tpName]), "");
Any help would be appreciated.


Re: sizeof operator not functioning - jasperschellekens - 26.04.2018

set the size manually in this case.
Код:
format(tpInfo[tpID][tpName], 50, "");



Re: sizeof operator not functioning - Phreak - 26.04.2018

Do you think anyone can help you with the information you gave us? You said it throws an error, it would be logical to at least post the error here.

My wild guess is that you didn't specifically make the variable a string. Can't help much more than that without more details.


Re: sizeof operator not functioning - iSpark - 26.04.2018

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
set the size manually in this case.
Код:
format(tpInfo[tpID][tpName], 50, "");
That is exactly what I do not wish to do. If this is the penultimate solution to this problem then I guess I will have no other option than using a MACRO for this.

Quote:
Originally Posted by Phreak
Посмотреть сообщение
Do you think anyone can help you with the information you gave us? You said it throws an error, it would be logical to at least post the error here.

My wild guess is that you didn't specifically make the variable a string. Can't help much more than that without more details.
[spoiler][/spoiler]


Re: sizeof operator not functioning - m4karow - 26.04.2018

why not use format(tpInfo[tpID][tpName], TP_NAME_SIZE, "");


Re: sizeof operator not functioning - iSpark - 26.04.2018

Quote:
Originally Posted by m4karow
Посмотреть сообщение
why not use format(tpInfo[tpID][tpName], TP_NAME_SIZE, "");
That's the solution that I used after I couldn't get sizeof to work. Which is odd TBH. I want to know what is the problem with the operator.


Re: sizeof operator not functioning - Phreak - 26.04.2018

The error says everything. It expects a closing bracket but it got an identifier.

sizeof wants to get the size of the variable itself (in this case the length of the array) so it expects tpInfo[][];


Re: sizeof operator not functioning - iSpark - 27.04.2018

Enums are eventually heterogeneous form of an array. At least that's what I thought so far. A slot within the enum returns 1, such confusion. I assumed the slot is reserved for the mentioned string. But the value that it's returning kinda threw me off guard.

My question is never the less answered. Thank you.

This may be closed.


Re: sizeof operator not functioning - SAKSHAMSLASH041 - 27.04.2018

May be syntax is wrong.....but wait I will respond quickly for it


Re: sizeof operator not functioning - iSpark - 27.04.2018

Using sizeof(tpInfo[][tpName]) was of no help. Same errors occured