Page 1 of 1

Craig's Useful Scripts

PostPosted: Fri Jul 25, 2014 6:33 pm
by Hblade
This might be just the start -- but here are a few useful scripts.

Code: Select all
/*
//---------------//
//Balance numbers, finds the center value between 2 values.
//    $Bal
//
//Toggle between 0 and 1
//    $tog
*/
int $bal(int val, int val2)
{
    int f_val=(val2+val)/2;
    return f_val;
}
int $tog(int value)
{
    return !(value);
}


//Place actor inbetween  2 other actors, requires $bal
void $center_objects(char *actor1, char*actor2)
{
    Actor *a=getclone(actor1);
    Actor *a2=getclone(actor2);
    int Valuex;
    int Valuey;
    Valuex=$bal(a->x, a2->x)-width/2;
    Valuey=$bal(a->y, a2->y)-height/2;
    x=Valuex;
    y=Valuey;
}
void $center_objects_x(char *actor1, char*actor2)
{
    Actor *a=getclone(actor1);
    Actor *a2=getclone(actor2);
    int Valuex;
    Valuex=$bal(a->x, a2->x)-width/2;
    x=Valuex;
}
void $center_objects_y(char *actor1, char*actor2)
{
    Actor *a=getclone(actor1);
    Actor *a2=getclone(actor2);
    int Valuey;
    Valuey=$bal(a->y, a2->y)-height/2;
    y=Valuey;
}

//defined a grid system, in case you want to align thins using a grid.
int $grid(int value, int grid_size)
{
    return value*grid_size;
}


The $ is an insignia.

Example:
x.png


Using $center_objects("left", "right"); you can center objects between object 1, and object 2, like you see in the image. the + will always be in the middle of the two.

$bal(number1, number2) gets the half-mark between the two numbers, as you can see in the image.

Simple things but useful.

Re: Craig's Useful Scripts

PostPosted: Tue Jul 29, 2014 1:05 pm
by digiot
Thanks, and carry on !
Hblade wrote:The $ is an insignia.

???
First I thought, we are in Bash now !
What does the dollar-sign do here, is it taken as a normal char ?

Cheers !

Re: Craig's Useful Scripts

PostPosted: Sat Aug 02, 2014 12:31 am
by Hblade
It was just for fun, haha.