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

Questions about use return and float bug(?)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hh2
AlliedModders Donor
Join Date: Sep 2010
Old 02-14-2014 , 14:53   Questions about use return and float bug(?)
Reply With Quote #1

Hello guys.
I have 2 questions:

1. Which function is better and/or faster, func1 or func2?
Code:
func1(id) {     if ( !alive )    return 1;         //do something         return 1; } func2(id) {     if ( alive )     {         // do something     } }
2. Look at example code:
Code:
new Float:g_float1[33]; new Float:g_float2[33][5]; g_float1[id] = get_gametime() + 10.0; g_float2[id][0] = get_gametime() + 10.0; print("%.2f", g_float1[id] - get_gametime()) // correct value = 10.00 print("%.2f", g_float2[id][0] - get_gametime()) // bad value = 14325235235.00 (or something like this)
Where is error?

Thanks for any help.

Last edited by hh2; 02-14-2014 at 15:15.
hh2 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-14-2014 , 15:53   Re: Questions about use return and float bug(?)
Reply With Quote #2

1. No difference. It's a matter of personal preference where I would chose the first because, to me, the code looks cleaner that way. I would however use "return" so the last return isn't necessary.
Code:
func1(id) {     if ( ! alive )         return;         //do something }

2. You tell me. The example you supplied is working. Share the real code or debug it yourself.
Code:
10.00
10.00
My guess is that you did this:
Code:
new Float:g_float1[33]; new Float:g_float2[33][5]; g_float1[id] = get_gametime() + 10.0;
g_float2[id][0] = get_systime() + 10.0;
print("%.2f", g_float1[id] - get_gametime()) // correct value = 10.00 print("%.2f", g_float2[id][0] - get_gametime()) // bad value = 14325235235.00 (or something like this)
Which results in this:
Code:
10.00
1392411392.00
__________________

Last edited by Black Rose; 02-14-2014 at 16:02.
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-14-2014 , 21:40   Re: Questions about use return and float bug(?)
Reply With Quote #3

Only choose func1() if you either have long code for the function or have a lot of checks to do before executing the code.
__________________
fysiks is offline
hh2
AlliedModders Donor
Join Date: Sep 2010
Old 02-15-2014 , 04:20   Re: Questions about use return and float bug(?)
Reply With Quote #4

Thanks for replies.

Here is example plugin to test things with floats, just say /test and watch a hudmessage:
Code:
#include <amxmodx> enum _:enums {     ONE,     TWO,     THREE }; new Float:float1[33]; new Float:float2[33][enums]; public plugin_init() {     register_plugin("float test", "0.1", "author")         register_clcmd("say /test", "t"); } public t(id) {     new Float:gametime = get_gametime();         float1[id] = gametime + 5.0;     float2[id][ONE] = gametime + 5.0; } public client_PreThink(id) {     if ( !is_user_alive(id) ) return PLUGIN_CONTINUE;         new Float:gametime =            get_gametime();     new Float:timeleft1 =             float1[id] - gametime;     new Float:timeleft2 =             float2[id][ONE] - gametime;         if ( timeleft1 >= 0.0 || timeleft2 >= 0.0 )     {         new text[256];                 formatex(text, 255, "float1: %.1f^nfloat2: %.1f", timeleft1, timeleft2);                 set_hudmessage(42, 255, 42, -1.0, -1.0, 0, 6.0, 0.1);         show_hudmessage(id, text);                 console_print(id, "f1: %.1f - f2: %.1f", timeleft1, timeleft2);     }         return PLUGIN_CONTINUE; }
Example logs from console:
Code:
f1: -146.9 - f2: 1094653824.0
f1: -147.0 - f2: 1094653824.0
Maybe error with enums? I think there is no error in code.

Last edited by hh2; 02-15-2014 at 04:23.
hh2 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-15-2014 , 04:31   Re: Questions about use return and float bug(?)
Reply With Quote #5

Try :

PHP Code:
enum _:enums
{
    
Float:ONE,
    
Float:TWO,
    
Float:THREE
}; 
When you use enum as pseudo structure, you should specify types.

Example :

PHP Code:
enum mDatas
{
    
m_iRandomInteger,
    
Float:m_flRandomFloat,
    
m_szRandomString[32],
    
Float:m_vecRandomVector[3]
}; 
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 02-15-2014 at 04:34.
ConnorMcLeod is offline
hh2
AlliedModders Donor
Join Date: Sep 2010
Old 02-15-2014 , 04:49   Re: Questions about use return and float bug(?)
Reply With Quote #6

Quote:
Originally Posted by ConnorMcLeod View Post
Try :

PHP Code:
enum _:enums
{
    
Float:ONE,
    
Float:TWO,
    
Float:THREE
}; 
Thank for your solution ConnorMcLeod.
Now its worked good, but this variables must be integer.

Maybe there is exists another solution?
hh2 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-15-2014 , 05:31   Re: Questions about use return and float bug(?)
Reply With Quote #7

Quote:
Originally Posted by hh2 View Post
Now its worked good, but this variables must be integer.
No. You have been given the only solution.
__________________

Last edited by fysiks; 02-15-2014 at 05:32.
fysiks is offline
hh2
AlliedModders Donor
Join Date: Sep 2010
Old 02-15-2014 , 06:00   Re: Questions about use return and float bug(?)
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
No. You have been given the only solution.
Ok, but i think this is bug with enums or float.

Thanks for any help, thread solved.
hh2 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-15-2014 , 08:15   Re: Questions about use return and float bug(?)
Reply With Quote #9

Quote:
Originally Posted by hh2 View Post
Ok, but i think this is bug with enums or float.
It's not.
If anything it could be a bug in the compiler, not warning you about tag mismatch. But I doubt that it can be easily fixed.
__________________

Last edited by Black Rose; 02-15-2014 at 08:16.
Black Rose 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 04:06.


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