AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Deviding a define number for two cases (https://forums.alliedmods.net/showthread.php?t=222166)

iBrazilian 07-30-2013 14:07

Deviding a define number for two cases
 
If BALL_AMOUNT is 6 then I'd like SPAWN_1 to spawn 3 entities and SPAWN_2, spawn the other 3 entities, so half of what is defined.

How would I accomplish this with enum cases?

PHP Code:

#define BALL_AMOUNT 6

enum
{
    
SPAWN_1,
    
SPAWN_2,
};

public 
makespawn()
{
    for(new 
i=0BALL_AMOUNTi++)
    {
        
spawnballs()
    }
}

spawnballs ()
{
    switch(
spawn)
    {
        case 
SPAWN_1:
        {
            
Add code to spawn entities around the map.
        }
        case 
SPAWN_2:
        {
            
Add code to spawn entities around the map.
        }
    }



Black Rose 07-30-2013 16:05

Re: Deviding a define number for two cases
 
Code:
#define BALL_AMOUNT 6 enum {     SPAWN_1 = 0, //I'm never sure if enum starts with 0 or 1.     SPAWN_2, }; public makespawn() {     for(new i=0; i < BALL_AMOUNT; i++)     {         spawnballs(i)     } } spawnballs (spawn) {     switch(spawn % 2) // I don't know what the operator is called. I would explain it as, what will get left over if you deduct "2" until no longer possible. So either it's 0 or 1.     {         case SPAWN_1:         {             Add code to spawn entities around the map.         }         case SPAWN_2:         {             Add code to spawn entities around the map.         }     } }

bibu 07-31-2013 12:18

Re: Deviding a define number for two cases
 
Quote:

Originally Posted by Black Rose (Post 2002384)
Code:
enum { SPAWN_1 = 0, //I'm never sure if enum starts with 0 or 1. SPAWN_2, };

Starts with 0. :wink:

mottzi 07-31-2013 15:56

Re: Deviding a define number for two cases
 
% is the modulo-operator


All times are GMT -4. The time now is 15:54.

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