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

Get time elapsed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 03-08-2023 , 18:08   Get time elapsed
Reply With Quote #1

what am i doing wrong here, im lost

time_elapsed.sma(26) : error 039: constant symbol has no size
time_elapsed.sma(31) : warning 209: function "time_elapsed" should return a value

Code:
#include <amxmodx> enum TimeData{     seconds,     units[8] } new Time[][TimeData] = {     { 365 * 24 * 60 * 60 , "year"   },      { 30 * 24 * 60 * 60 , "month"  },           { 24 * 60 * 60 , "day"    },                { 60 * 60 , "hour"   },                     { 60 , "minute" },                      { 1 , "second" } } public plugin_cfg()     server_print(time_elapsed(get_systime()-random(100000))) public time_elapsed(past){     new now = get_systime() - past     if (now < 1)         return "just now"         for (new i = 0; i < sizeof(Time); i++){         new unit = now / Time[i][seconds]         if (unit >= 1)             return (fmt("%d %s%s ago", unit, Time[i][units], unit > 1 ? "s" : ""))     } }
__________________
bigdaddy424 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-08-2023 , 18:48   Re: Get time elapsed
Reply With Quote #2

The "constant symbol has no size" error seems to be caused by:

Code:
return "just now"
I'd guess that it's because it conflicts with the other return value that you're returning. If you replace the aforementioned line with:

Code:
return fmt("just now")
it will compile.

Regarding the "should return a value" warning is because there is, from a compilation perspective, a chance that neither of the return statements that you have in your function will execute. So, you need to account for that. The easiest way to resolve this is to add a return statement at the very end of the function just like the "just now" one but with different text. I've actually seen some code out there where they would put "this code should never execute" for cases like this where you are absolutely sure it won't execute.
__________________

Last edited by fysiks; 03-08-2023 at 18:49.
fysiks is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 03-08-2023 , 19:48   Re: Get time elapsed
Reply With Quote #3

i removed the if condition and put return fmt("just now") as an absolute return in case for loop iterates without returning a value
__________________
bigdaddy424 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-08-2023 , 22:56   Re: Get time elapsed
Reply With Quote #4

That should work too.
__________________
fysiks is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 03-10-2023 , 22:37   Re: Get time elapsed
Reply With Quote #5

i does the job ig
__________________
bigdaddy424 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 08:14.


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