AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   error 033: array must be indexed(variable "g_fColor") (https://forums.alliedmods.net/showthread.php?t=343286)

amirwolf 07-08-2023 08:26

error 033: array must be indexed(variable "g_fColor")
 
Hello
What I was trying to do
Trying to add some random color to the door
PHP Code:

#define bar_Random(%1) %1 == -1 ? g_fColor[random(MAX_COLORS)] : %1

set_pev(g_iEntBarrier,pev_rendercolor,bar_Random(g_eSettings[BARRIER_COLOR][0],g_eSettings[BARRIER_COLOR][1],g_eSettings[BARRIER_COLOR][2])); 


lexzor 07-08-2023 10:41

Re: error 033: array must be indexed(variable "g_fColor")
 
post how you declare g_fColor

amirwolf 07-08-2023 11:39

Re: error 033: array must be indexed(variable "g_fColor")
 
PHP Code:

#define MAX_COLORS 25
new const Float:g_fColor[MAX_COLORS][3] = 
{
    {
200.0000.0000.0},
    {
255.0083.0073.0},
    {
255.0117.0056.0},
    {
255.0174.0066.0},
    {
255.0207.0171.0},
    {
252.0232.0131.0},
    {
254.0254.0034.0},
    {
059.0176.0143.0},
    {
197.0227.0132.0},
    {
000.0150.0000.0},
    {
120.0219.0226.0},
    {
135.0206.0235.0},
    {
128.0218.0235.0},
    {
000.0000.0255.0},
    {
146.0110.0174.0},
    {
255.0105.0180.0},
    {
246.0100.0175.0},
    {
205.0074.0076.0},
    {
250.0167.0108.0},
    {
234.0126.0093.0},
    {
180.0103.0077.0},
    {
149.0145.0140.0},
    {
000.0000.0000.0},
    {
255.0255.0255.0},
    {
000.0000.0000.0}



Celena Luna 07-08-2023 13:16

Re: error 033: array must be indexed(variable "g_fColor")
 
I think it is because bar_Random only take 1 parameters, not 3

Bugsy 07-08-2023 15:54

Re: error 033: array must be indexed(variable "g_fColor")
 
Try this
PHP Code:

new iColorIndex bar_Randomg_eSettingsBARRIER_COLOR ][ ]  ); 
set_pev(g_iEntBarrier,pev_rendercolor,g_eSettings[iColorIndex][0],g_eSettings[iColorIndex][1],g_eSettings[iColorIndex][2])); 


amirwolf 07-09-2023 01:45

Re: error 033: array must be indexed(variable "g_fColor")
 
Same error again
why when i add this
HTML Code:

random_float(0.0, 255.0)
Only red color is visible

lexzor 07-09-2023 07:08

Re: error 033: array must be indexed(variable "g_fColor")
 
since g_fColor has float values, bar_Random is made to return float values

PHP Code:

#define bar_Random(%1) %1 == -1 ? g_fColor[random(MAX_COLORS)] : %1 

not the index of the colors from g_fColors

since the value of g_fColors is hardcorded, you could return the index of the colors by using random(sizeof(g_fColors)-1)

amirwolf 07-09-2023 08:17

Re: error 033: array must be indexed(variable "g_fColor")
 
The error is now fixed
But it still does not work, random values ​​are not added

fysiks 07-09-2023 19:00

Re: error 033: array must be indexed(variable "g_fColor")
 
If you're just trying to get a random index value for the colors array, you simply do that first:

PHP Code:

new iRandomIndex random(sizeof(g_fColors)) 

Then, you can choose to use that or whatever settings you have.

PHP Code:

new ActualColorIndex = (setting == -iRandomIndex setting

then use this index for g_fColor:

PHP Code:

new red g_fColor[ActualColorIndex][0]
new 
green g_fColor[ActualColorIndex][1]
new 
blue g_fColor[ActualColorIndex][2

If you want each component of the color to be independently random then you need to do the same thing for each of the three components.

I think you're complicating things by trying to be clever with your code. Stop using the preprocessor and write basic code first, it doesn't have to be pretty or scalable, just write it to make it work. Get that working and then optimize later.

Quote:

Originally Posted by lexzor (Post 2806963)
since the value of g_fColors is hardcorded, you could return the index of the colors by using random(sizeof(g_fColors)-1)

The function "random" is designed specifically for indexing arrays based on the size of the array so you should not subtract 1 unless you're intentionally trying to exclude the last value in the array.

amirwolf 07-10-2023 04:01

Re: error 033: array must be indexed(variable "g_fColor")
 
It has always been difficult for me to understand
I will try my best
thank you


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

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