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

Solved pass 'enum' as parameter


Post New Thread Reply   
 
Thread Tools Display Modes
wilian159
Member
Join Date: Dec 2013
Old 07-24-2022 , 19:17   Re: pass 'enum' as parameter
Reply With Quote #11

Quote:
Originally Posted by fysiks View Post
My original suggestion works perfectly for me:

PHP Code:
enum myEnum {NAME[32], Float:CHANCE};
new 
myArray[][myEnum] = 
{
    {
"item1"10.1},
    {
"item2"20.1},
    {
"item3"30.1},
    {
"item4"40.1},
}


public 
cmdTest()
{
    
server_print("sum:  %f"myFunction(myArraysizeof myArrayCHANCE))
}

stock Float:myFunction(array[][], size, const index)
{
    new 
Float:fProb 0.0
    
for( new 0sizei++ )
    {
        
fProb += Float:array[i][index]
    }
    return 
fProb

Output is:

Code:
sum:  100.400001
Which is correct. Without the "Float:" where I said to put it, I get

Code:
sum:  4409498112.000000
worked, thank you!
__________________
wilian159 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 19:22   Re: pass 'enum' as parameter
Reply With Quote #12

Glad you got it working. Apology accepted.

P.S. since you're using these values in a ratiometric way (i.e. the numbers don't actually equate to percent probability), it might be better to simply do everything with integers. I do this here. I get the "total" using a global variable but could be internalized or passed in as a argument.
__________________

Last edited by fysiks; 07-24-2022 at 20:33. Reason: fix url
fysiks is offline
wilian159
Member
Join Date: Dec 2013
Old 07-24-2022 , 19:52   Re: pass 'enum' as parameter
Reply With Quote #13

Quote:
Originally Posted by fysiks View Post
Glad you got it working. Apology accepted.

P.S. since you're using these values in a ratiometric way (i.e. the numbers don't actually equate to percent probability), it might be better to simply do everything with integers. I do this here. I get the "total" using a global variable but could be internalized or passed in as a argument.
I can't see the link, but yes, this 'scheme' is by precise probability, if I use it in integers it won't be so cool,

the item 'Bazooka' has a 0.01% chance, I looped it 2000 times and I don't see it, it's very good



it's very accurate
__________________

Last edited by wilian159; 07-24-2022 at 19:53.
wilian159 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 20:40   Re: pass 'enum' as parameter
Reply With Quote #14

Quote:
Originally Posted by wilian159 View Post
I can't see the link, but yes, this 'scheme' is by precise probability, if I use it in integers it won't be so cool,

the item 'Bazooka' has a 0.01% chance, I looped it 2000 times and I don't see it, it's very good

it's very accurate
Yes, I know, and that is easy to achieve because it's ratiometric. Just multiply all your values by a factor of 10 to achieve finer resolutions. In your case, to achieve the same probabilities as your original code you would use: 5850, 6170, 1, 10, 250, respectively.

FYI, the way you're doing it now will not result in 58.5% probability of getting "Chinelo" unless all the values in the xProbItems array added up to 100.0. It will result in a 47.6% probability.

Also, I fixed the link. Looks like I had some other code on my clipboard.
__________________

Last edited by fysiks; 07-24-2022 at 20:41.
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 05:00.


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