Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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
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 07:45.


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