Craig's Useful Scripts

Game Editor comments and discussion.

Craig's Useful Scripts

Postby Hblade » Fri Jul 25, 2014 6:33 pm

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.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Craig's Useful Scripts

Postby digiot » Tue Jul 29, 2014 1:05 pm

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 !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Re: Craig's Useful Scripts

Postby Hblade » Sat Aug 02, 2014 12:31 am

It was just for fun, haha.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest