Float positive and negative calculation isn't working
#1

So basically, I'm trying to create a random generation of "tiles", but I can't calculate out the X and Y position from 0.0, 0.0 by using negative numbers but I can succeed with doing it with positive numbers.

As seen here; tile 4 is supposed to be on the corner of tile 1, west-south, not north-east.


Here's how their deployment is;
PHP код:
    public OnGameModeInit() {
        
CreateTile(TILE_TYPE_GRASS00);
        
CreateTile(TILE_TYPE_GRASS10);
        
CreateTile(TILE_TYPE_GRASS01);
        
CreateTile(TILE_TYPE_GRASS, -1, -1);
        return 
1;
    } 
And the function is as following;
PHP код:
stock CreateTile(typexy) {
    new 
id CreateObject(TILE_MODEL_ID, (>= 0)?(x*125):(x*(-125)), (>= 0)?(y*125):(y*(-125)), 30.0000);
    new 
string[144];
    
format(stringsizeof string"Tile: %i\nPosition: %i - %i"id, (>= 0)?(x*125):(x*(-125)), (>= 0)?(y*125):(y*(-125)));
    
Create3DTextLabel(string0x1CC4FCFF, (>= 0)?(x*125):(x*(-125)), (>= 0)?(y*125):(y*(-125)), 30.01000.000);
    switch(
type) {
        case 
TILE_TYPE_GRASS: {
            
SetObjectMaterial(id09495"vict_sfw""Grass"0);
            for(new 
Float:gYY = -62.5gYY 62.5gYY += (float(random(50)+1)*0.1)+1)
                for(new 
Float:gX = -62.5Float:gY float(random(50)+1)*0.1gX 62.5gX += (float(random(50)+1)*0.1)+1gY float(random(50)+1)*0.1)
                    
CreateDynamicObject(TILE_OBJECT_GRASS, ((>= 0)?(x*125):(x*(-125)))+gX, (((>= 0)?(y*125):(y*(-125)))+gY)-gYY30000);
        }
    }
    
staticTiles[id][staticTile_ID] =     id;
    
staticTiles[id][staticTile_Type] =     type;

Any ideas of what I'm doing wrong?


https://*********/j-81qEOxk6E
Reply
#2

-1Ч(-1)=+1
-1Ч1=-1

So your above calculations are always positive. You don't need to check if value of x and y is negative or positive.
Just keep them as they are with Ч125.
Reply
#3

Quote:
Originally Posted by jlalt
Посмотреть сообщение
-1Ч(-1)=+1
-1Ч1=-1

So your above calculations are always positive. You don't need to check if value of x and y is negative or positive.
Just keep them as they are with Ч125.
Ahh yes! I should've paid more attention to school I guess, meh, thanks, pal.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)