Raised This Month: $ Target: $400
 0% 

[ Solved ] While ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Aooka
Veteran Member
Join Date: Aug 2011
Location: Villeurbanne
Old 05-12-2012 , 18:01   [ Solved ] While ?
Reply With Quote #1

Hello everyone,

Today, i have a new question for you. It's about the loop while
So my question is very simple :

Have you got any exemple of code with the loop while and with if it's possible a variable ...
__________________
Pawn ? Useless
Aooka is offline
Ex1ne
Senior Member
Join Date: Oct 2011
Location: Norway
Old 05-12-2012 , 18:21   Re: While ?
Reply With Quote #2

Well, here's an example code used for my time played plugin, the variable is here an example.
I hope you learn something with this.
PHP Code:
#include <amxmodx>
#include <amxmisc>

new seconds 530 // random time in seconds our "client" has spent on the server

public plugin_init() 
{
    
register_clcmd"say /time""zaa" )
}
public 
zaa(id)
{
    new 
hoursminutes // integer for hours & minutes
    
    
while( seconds >= 60 // This will continue to pass through untill variable: seconds, is under 60.
    
{
        
minutes++
        
seconds -= 60 
    
}
    
    
    while( 
minutes >= 60 // Same as above, only seconds -> minutes
    
{
        
hours++
        
minutes -= 60
    
}
    
client_print(idprint_chat"You have played %i hours, %i minutes & %i seconds"hoursminutesseconds// print it

__________________
Ex1ne is offline
Aooka
Veteran Member
Join Date: Aug 2011
Location: Villeurbanne
Old 05-12-2012 , 18:28   Re: While ?
Reply With Quote #3

Oh thanks a lot ! I did not expect
__________________
Pawn ? Useless
Aooka is offline
Aooka
Veteran Member
Join Date: Aug 2011
Location: Villeurbanne
Old 05-12-2012 , 18:50   Re: While ?
Reply With Quote #4

Hum the include <amxmisc> is useless i think ^^
__________________
Pawn ? Useless
Aooka is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-13-2012 , 02:24   Re: While ?
Reply With Quote #5

There are examples of while loops all over the internet.

Also, the code above can be done without any loops.
__________________
fysiks is offline
Ex1ne
Senior Member
Join Date: Oct 2011
Location: Norway
Old 05-13-2012 , 08:35   Re: While ?
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
There are examples of while loops all over the internet.

Also, the code above can be done without any loops.
How? O__o
__________________
Ex1ne is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-13-2012 , 08:48   Re: While ?
Reply With Quote #7

PHP Code:
seconds 60 // returns seconds
seconds 60 // returns minutes
seconds 60 60 // returns hours 
__________________

Last edited by <VeCo>; 05-13-2012 at 08:48.
<VeCo> is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-13-2012 , 16:37   Re: While ?
Reply With Quote #8

Quote:
Originally Posted by <VeCo> View Post
PHP Code:
seconds 60 // returns seconds
seconds 60 // returns minutes
seconds 60 60 // returns hours 
If the time is actually 1 hour 15 minutes and 32 seconds your code will return 1 hour 75 minutes and 32 seconds. That is OK if you are not going to only use minutes and seconds but not if you want to use all three.

This is the correct method when wanting to use days, hours, minutes, and seconds (days can easily be omitted):

PHP Code:
        iDays iTimeLeft 86400
        iHours 
iTimeLeft 86400 3600
        iMinutes 
iTimeLeft 3600 60
        iSeconds 
iTimeLeft 60 
__________________

Last edited by fysiks; 05-13-2012 at 16:37.
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 00:26.


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