Raised This Month: $ Target: $400
 0% 

Solved error 052: multi-dimensional arrays must be fully initialized


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AnimalMonster
Senior Member
Join Date: May 2020
Old 12-09-2022 , 12:31   error 052: multi-dimensional arrays must be fully initialized
Reply With Quote #1

I really don't get how enum + multi-dimensional arrays should work together or i don't know but i thought this would work

PHP Code:
enum _RegisterData
{
    
RD_SystemName,
    
RD_Name,
    
RD_Model,
    
RD_Health,
    
RD_Gravity,
    
RD_Speed,
    
RD_JumpVelocity,
    
RD_Gender,
    
RD_DeadSound[2],
    
RD_KillSound[2],
    
RD_HitSound[2]
}

new 
g_DataKeys[RegisterData][] = {
    
"",
    
"NAME",
    
"MODEL",
    
"HEALTH",
    
"GRAVITY",
    
"SPEED",
    
"JUMP_POWER",
    
"GENDER",
    {
"DEAD_SOUND1""DEAD_SOUND2"},
    {
"KILL_SOUND1""KILL_SOUND2"},
    {
"PAIN_SOUND1""PAIN_SOUND2"},

Edit: Solved..
PHP Code:
enum _RegisterData
{
    
RD_SystemName,
    
RD_Name,
    
RD_Model,
    
RD_Health,
    
RD_Gravity,
    
RD_Speed,
    
RD_JumpVelocity,
    
RD_Gender,
    
RD_DeadSound[2],
    
RD_KillSound[2],
    
RD_HitSound[2]
}

new 
g_DataKeys[RegisterData][] = {
    
"",
    
"NAME",
    
"MODEL",
    
"HEALTH",
    
"GRAVITY",
    
"SPEED",
    
"JUMP_POWER",
    
"GENDER",
    
"DEAD_SOUND1"
    
"DEAD_SOUND2",
    
"KILL_SOUND1"
    
"KILL_SOUND2",
    
"PAIN_SOUND1"
    
"PAIN_SOUND2"

And i have to use it like
PHP Code:
g_DataKeys[RD_DeadSound][0

Last edited by AnimalMonster; 12-09-2022 at 13:15.
AnimalMonster is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-09-2022 , 19:56   Re: error 052: multi-dimensional arrays must be fully initialized
Reply With Quote #2

All of the variables defined in your RegisterData enum are integers, not strings. Strings themselves are arrays so your enum needs to have the extra dimension for the length of the string (plus 1).

Here is an example of properly storing strings with enums (including examples for using it as a global dataset and as player-specific datasets):

PHP Code:
enum _:MyEnum {
    
STRING1[32],
    
STRING2[32]
}

// Save one global set of data
g_GlobalData[MyEnum] = {
    
"Hello",
    
"World"
}

server_print("%s"g_GlobalData[STRING1]) // Get and use "Hello"


// Save data per-player
new g_UserData[MAXPLAYERS+1][MyEnum// Data gets populated as needed

server_print("%s"g_UserData[id][STRING1]) // Get and use STRING1 for specific player 
I'm not entirely sure what you're trying to do based on your post. What you claim solves your problems doesn't make much sense to me. I'm quite sure that g_DataKeys[RD_DeadSound][0] would reference just the first character of the string.
__________________

Last edited by fysiks; 12-09-2022 at 20:23.
fysiks is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 12-14-2022 , 10:52   Re: error 052: multi-dimensional arrays must be fully initialized
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
All of the variables defined in your RegisterData enum are integers, not strings. Strings themselves are arrays so your enum needs to have the extra dimension for the length of the string (plus 1).

Here is an example of properly storing strings with enums (including examples for using it as a global dataset and as player-specific datasets):

PHP Code:
enum _:MyEnum {
    
STRING1[32],
    
STRING2[32]
}

// Save one global set of data
g_GlobalData[MyEnum] = {
    
"Hello",
    
"World"
}

server_print("%s"g_GlobalData[STRING1]) // Get and use "Hello"


// Save data per-player
new g_UserData[MAXPLAYERS+1][MyEnum// Data gets populated as needed

server_print("%s"g_UserData[id][STRING1]) // Get and use STRING1 for specific player 
I'm not entirely sure what you're trying to do based on your post. What you claim solves your problems doesn't make much sense to me. I'm quite sure that g_DataKeys[RD_DeadSound][0] would reference just the first character of the string.
Exactly, all the integers of my Enumeration are integers but as you can see there are 3 lines defining another 3 integers as with of two values, and as you maybe know enumeration's total are made up by all the dimension sizez, if there aren't any specified automatically 1, and those 3 lines add twice to the enumeration as different values so what i wrote above makes perfect sense as i have to specify which RD_DeadSound i want to use.

As i use it for two different things:
- Creating Dynamic Arrays
- Creating the variable DataKeys

I don't think i would have been much useful to create and use a different enumeration and still i'd have to add that [2] cuz i'm too lazy to add more lines and i don't want to make my code any bigger.

So to exemplify:
We have
PHP Code:
enum AttentionSeek {
    
I_Want_Attention
    You_Lost
[2]

and a variable
PHP Code:
new glbVariableForStrings[AttentionSeek][] = {
    
"I Want Attention",
    
"You Lost 1",
    
"You Lost 2"

Using "AttentionSeek" would give us the number 3 since "You_Lost" has a dimension size of 2, but how do we use it? How do you know which "You_Lost" you are using? To answer this we have to look at something.. if we have a dimension with a size 2 in a Enumeration variable, that extra dimension will be used before using the variable's other dimensions that come after the dimension we choose to add the size of "AttentionSeek", which is the first dimension in the example above, so:
PHP Code:
glbVariableForStrings[You_Lost][0][0
would give us our first character of "You Lost 1".

Last edited by AnimalMonster; 12-14-2022 at 11:03.
AnimalMonster is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-14-2022 , 21:29   Re: error 052: multi-dimensional arrays must be fully initialized
Reply With Quote #4

If you're using the enum strictly as an enum then what you're saying is correct. However, I interpreted what you were doing is using the enum as a pseudo-struct. When using it as if it were struct, the it should fully define the data that each element should contain (which is not the case in your version of the code). This was the basis of my response since this is how I would view your code's goal based on the little code that was provided. The strict enum usage didn't occur to me immediately when reading your post.
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:07.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode