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

Deviding a define number for two cases


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iBrazilian
Senior Member
Join Date: May 2011
Old 07-30-2013 , 14:07   Deviding a define number for two cases
Reply With Quote #1

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.
        }
    }

__________________
Pokemod Season 5 [ |||||||||| Complete]
iBrazilian is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-30-2013 , 16:05   Re: Deviding a define number for two cases
Reply With Quote #2

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.         }     } }
__________________

Last edited by Black Rose; 07-30-2013 at 17:24.
Black Rose is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 07-31-2013 , 12:18   Re: Deviding a define number for two cases
Reply With Quote #3

Quote:
Originally Posted by Black Rose View Post
Code:
enum { SPAWN_1 = 0, //I'm never sure if enum starts with 0 or 1. SPAWN_2, };
Starts with 0.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-31-2013 , 15:56   Re: Deviding a define number for two cases
Reply With Quote #4

% is the modulo-operator
mottzi is offline
Send a message via MSN to mottzi
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 02:27.


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