AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to use "--"? (https://forums.alliedmods.net/showthread.php?t=85947)

biscuit628 02-18-2009 09:14

How to use "--"?
 
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..

Bugsy 02-18-2009 09:19

Re: How to use "--"?
 
Quote:

Originally Posted by biscuit628 (Post 763845)
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

Spunky 02-18-2009 14:21

Re: How to use "--"?
 
Code:
#define GAMESTARTTIME 20

is the same as:

Code:
new const g_iGameStartTime = 20

padilha007 02-18-2009 14:31

Re: How to use "--"?
 
Gamestarttime = Gamestarttime - 1 ?

anakin_cstrike 02-18-2009 14:42

Re: How to use "--"?
 
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") }

fysiks 02-18-2009 19:55

Re: How to use "--"?
 
Quote:

Originally Posted by Spunky (Post 764126)
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.

Spunky 02-19-2009 03:54

Re: How to use "--"?
 
Right, which is effectively the same as using a constant variable. Nobody's questioning how the preprocessor works. O_o

YamiKaitou 02-19-2009 10:40

Re: How to use "--"?
 
Quote:

Originally Posted by Spunky (Post 764430)
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.

Spunky 02-19-2009 11:55

Re: How to use "--"?
 
Take a closer look at what I said...

Quote:

Originally Posted by Spunky (Post 764430)
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. -_-

stupok 02-20-2009 18:31

Re: How to use "--"?
 
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.


All times are GMT -4. The time now is 16:51.

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