Help with 'new'
#1

I had this doubt when writing codes for someone in 'Scripting Help'.

The problem is..
Imagine this is my code:
PHP код:
OnPlayerConnect(playerid)
{
    
count++;
    new 
hello[count][128];

Can 'new' be created with its size set to any variable?
If no, is there any other way?
Reply
#2

It can be, yes. Though, I don't understand fully what you mean by that code.
Reply
#3

Quote:
Originally Posted by BleverCastard
Посмотреть сообщение
It can be, yes. Though, I don't understand fully what you mean by that code.
You are wrong. Array sizes MUST be determined before compilation. You cannot use a variable as a size.

The above code would produce the following errors:
Quote:

error 008: must be a constant expression; assumed zero
error 009: invalid array size (negative, zero or out of bounds)
error 036: empty statement
fatal error 107: too many error messages on one line

You have to set the array size to the highest possible value that might be used.
Reply
#4

Okay, thanks for your help.

Also, if anyone knows any other answer, please post it.
Reply
#5

There is no other answer. You must set a constant value (known at compile time). The only other option is to use foreach/y_iterate/linked lists with plugins, but only if they're relevant to what you're trying to do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)