Raised This Month: $ Target: $400
 0% 

How to use "--"?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
biscuit628
Senior Member
Join Date: Jun 2007
Location: 香港HongKong
Old 02-18-2009 , 09:14   How to use "--"?
Reply With Quote #1

PHP Code:
#include <amxmodx>
#define Gamestarttime 20



public downtime(){
    
client_print(0print_center"%d Seconds Until Gamestart.."Gamestarttime)
    
Gamestarttime--
    if(
Gamestarttime<0)
        
restart_map()
    else
        
set_task(1.0"downtime")
    
    return 
PLUGIN_HANDLED
}


public 
restart_map() {    
    
set_hudmessage(01002000.050.6520.026.00.010.12)     
    
show_hudmessage(0,"Game will start after restart 3 times!")    
    
set_cvar_num("mp_friendlyfire",0)  
    
set_cvar_num("sv_maxspeed",0)   
    
server_cmd("amx_restart3times")
 
    return 
PLUGIN_HANDLED
   
}   


public 
plugin_init() {   
   
register_plugin("Auto-Restart","1.00","Test")   
   
register_event("TextMsg","downtime","a","2&#Game_C")  
   return 
PLUGIN_CONTINUE     

Cannot compile..
Please fix my code..
biscuit628 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-18-2009 , 09:19   Re: How to use "--"?
Reply With Quote #2

Quote:
Originally Posted by biscuit628 View Post
PHP Code:
#include <amxmodx>
#define Gamestarttime 20



public downtime(){
    
client_print(0print_center"%d Seconds Until Gamestart.."Gamestarttime)
    
Gamestarttime--
    if(
Gamestarttime<0)
        
restart_map()
    else
        
set_task(1.0"downtime")
    
    return 
PLUGIN_HANDLED
}


public 
restart_map() {    
    
set_hudmessage(01002000.050.6520.026.00.010.12)     
    
show_hudmessage(0,"Game will start after restart 3 times!")    
    
set_cvar_num("mp_friendlyfire",0)  
    
set_cvar_num("sv_maxspeed",0)   
    
server_cmd("amx_restart3times")
 
    return 
PLUGIN_HANDLED
   
}   


public 
plugin_init() {   
   
register_plugin("Auto-Restart","1.00","Test")   
   
register_event("TextMsg","downtime","a","2&#Game_C")  
   return 
PLUGIN_CONTINUE     

Cannot compile..
Please fix my code..
You have Gamestarttime defined as a constant therefore cannot be changed during runtime. Try changing

#define Gamestarttime 20

to

new g_GameStartTime = 20
__________________
Bugsy is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 02-18-2009 , 14:21   Re: How to use "--"?
Reply With Quote #3

Code:
#define GAMESTARTTIME 20

is the same as:

Code:
new const g_iGameStartTime = 20
Spunky is offline
Send a message via AIM to Spunky
padilha007
Senior Member
Join Date: Jul 2008
Old 02-18-2009 , 14:31   Re: How to use "--"?
Reply With Quote #4

Gamestarttime = Gamestarttime - 1 ?
__________________

padilha007 is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 02-18-2009 , 14:42   Re: How to use "--"?
Reply With Quote #5

Gamestarttime = Gamestarttime - 1;
Gamestarttime -= 1;
Gamestarttime--;

All are the same.

Code:
#include <amxmodx> new g_Counter = 10; public plugin_init()     register_event("TextMsg","downtime","a","2&#Game_C") public downtime() {     g_Counter = 10;     set_task( 1.0, "countdown", 123, _, _, "b" ); }     public countdown() {     if( --g_Counter > 0 )         client_print(0, print_center, "%d Seconds Until Gamestart..", g_Counter);     else     {         remove_task( 123 );         restart_map();     } } restart_map() {         set_hudmessage(0, 100, 200, 0.05, 0.65, 2, 0.02, 6.0, 0.01, 0.1, 2)         show_hudmessage(0,"Game will start after restart 3 times!")             set_cvar_num("mp_friendlyfire",0)       set_cvar_num("sv_maxspeed",0)       server_cmd("amx_restart3times") }
__________________

anakin_cstrike is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-18-2009 , 19:55   Re: How to use "--"?
Reply With Quote #6

Quote:
Originally Posted by Spunky View Post
Code:
#define GAMESTARTTIME 20
is the same as:

Code:
new const g_iGameStartTime = 20
That is incorrect. #define is a preprocessor directive for the compiler. It puts "20" in your code everywhere that it finds GAMESTARTTIME before it is compiled.

new const will allocate memory to store the integer 20.

This is how I understand it.

Last edited by fysiks; 02-18-2009 at 20:01.
fysiks is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 02-19-2009 , 03:54   Re: How to use "--"?
Reply With Quote #7

Right, which is effectively the same as using a constant variable. Nobody's questioning how the preprocessor works. O_o
Spunky is offline
Send a message via AIM to Spunky
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-19-2009 , 10:40   Re: How to use "--"?
Reply With Quote #8

Quote:
Originally Posted by Spunky View Post
Right, which is effectively the same as using a constant variable. Nobody's questioning how the preprocessor works. O_o
No, they are not the same. const are computed during runtime and define is done at compile. new const will allocate memory, define does not.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 02-19-2009 , 11:55   Re: How to use "--"?
Reply With Quote #9

Take a closer look at what I said...

Quote:
Originally Posted by Spunky View Post
Nobody's questioning how the preprocessor works. O_o
You still don't understand that nobody is questioning that. Nobody is talking about the technical difference between a macro and a constant variable. The effect, in this context, is exactly the same. You cannot change the value of a macro once defined. Therefore, it IS effectively the same thing as a constant variable in this context. Please pay attention.

I'm going to start spelling everything out from the start from now on. -_-
Spunky is offline
Send a message via AIM to Spunky
stupok
Veteran Member
Join Date: Feb 2006
Old 02-20-2009 , 18:31   Re: How to use "--"?
Reply With Quote #10

You didn't provide a context. First, you said they were the same, which is false. Next, you said they were "effectively" the same, which is also false, as detailed above.

The only similarity between the two is that you cannot change the value once it's been set. The "effect" is not the same for the machine running the program. For the programmer, I guess the two types can be used interchangeably, but I'm not sure about that. So, in that context you may be correct.
__________________

Last edited by stupok; 02-20-2009 at 18:38.
stupok 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 16:51.


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