Raised This Month: $51 Target: $400
 12% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 07-08-2023 , 08:26   error 033: array must be indexed(variable "g_fColor")
Reply With Quote #1

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])); 
__________________

Last edited by amirwolf; 07-08-2023 at 09:13.
amirwolf is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-08-2023 , 10:41   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #2

post how you declare g_fColor
lexzor is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 07-08-2023 , 11:39   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #3

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}

__________________
amirwolf is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-08-2023 , 13:16   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #4

I think it is because bar_Random only take 1 parameters, not 3
__________________
My plugin:

Last edited by Celena Luna; 07-08-2023 at 13:31.
Celena Luna is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-08-2023 , 15:54   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #5

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])); 
__________________
Bugsy is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 07-09-2023 , 01:45   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #6

Same error again
why when i add this
HTML Code:
random_float(0.0, 255.0)
Only red color is visible
__________________
amirwolf is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-09-2023 , 07:08   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #7

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)
lexzor is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 07-09-2023 , 08:17   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #8

The error is now fixed
But it still does not work, random values ​​are not added
__________________
amirwolf is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-09-2023 , 19:00   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #9

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 View Post
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.
__________________
fysiks is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 07-10-2023 , 04:01   Re: error 033: array must be indexed(variable "g_fColor")
Reply With Quote #10

It has always been difficult for me to understand
I will try my best
thank you
__________________
amirwolf 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 09:48.


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