AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   const in function (https://forums.alliedmods.net/showthread.php?t=156065)

reinert 04-30-2011 13:32

const in function
 
Hey, how can I add a const parameter in function like:
PHP Code:

new const RandomColors[3][] = {
"255, 0, 0",
"0, 255, 0",
"0, 0, 255"
}

set_dhudmessageRandomColors[random_num(1,3)], 0.030.21212.04.00.22.0 ); 

It says:
Quote:

Error: Argument type mismatch (argument 1)

hleV 04-30-2011 13:38

Re: const in function
 
I guess Arkshine didn't add const for colors.

BTW change random_num(1, 3) to random(sizeof RandomColors).

reinert 04-30-2011 13:47

Re: const in function
 
So is there another way of getting (R,G,B) colors from my list and adding them to set_dhudmessage function ?

Bugsy 04-30-2011 13:51

Re: const in function
 
May need to mod the function on your own. I've never seen\used it but:

PHP Code:

new const RandomColors[3][] = 
{
   
"255, 0, 0",
   
"0, 255, 0",
   
"0, 0, 255"
};

public 
YourFunc( const szRGB[] )
{
     
//parse and use colors here
}

//Call function
YourFuncRandomColorsrandomsizeofRandomColors ) ) ] ) 

or

PHP Code:

enum Colors
{
    
Red,
    
Green,
    
Blue
}

new const 
RandomColors][ Colors ] = 
{
    { 
255 },
    { 
255 },
    { 
255 }
};

public 
YourFunc( const iRGBColors ] )
    
server_print"R=%d G=%d B=%d" iRGBRed ] , iRGBGreen ] , iRGBBlue ] );

public 
lols()
    
YourFuncRandomColorsrandomsizeofRandomColors ) ) ] ) 


Arkshine 04-30-2011 13:54

Re: const in function
 
set_dhudmessage mimic set_hudmessage, meaning the color is not a string.

set_dhudmessage( red, green, blue, ... );

reinert 04-30-2011 13:57

Re: const in function
 
how can I parse it ?
PHP Code:

new rgb;
parse(RandomColors[random(3)], r,b)

set_dhudmessagerg... ) 

Like this ? But this is not working :(

Arkshine 04-30-2011 14:08

Re: const in function
 
Why working with string ?

ConnorMcLeod 04-30-2011 14:11

Re: const in function
 
- Was said that colors are not string and are 3 different params
- You mis-use parse native
- If you use parse you would have to convert string colors into int colors.

PHP Code:

new const RandomColors[][] = {
    {
25500},
    {
02550},
    {
00255}
}

new 
iRandom randomsizeof(RandomColors) )

set_dhudmessage(RandomColors[0][iRandom],RandomColors[1][iRandom],RandomColors[2][iRandom], 0.030.21212.04.00.22.0 ); 


reinert 04-30-2011 14:14

Re: const in function
 
Quote:

Originally Posted by ConnorMcLeod (Post 1460796)
- Was said that colors are not string and are 3 different params
- You mis-use parse native
- If you use parse you would have to convert string colors into int colors.

PHP Code:

new const RandomColors[][] = {
    {
25500},
    {
02550},
    {
00255}
}

new 
iRandom randomsizeof(RandomColors) )

set_dhudmessage(RandomColors[0][iRandom],RandomColors[1][iRandom],RandomColors[2][iRandom], 0.030.21212.04.00.22.0 ); 


Thanks, that should be good ;)


All times are GMT -4. The time now is 04:18.

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