Page 1 of 2

Community functions

PostPosted: Tue May 20, 2014 6:51 am
by barney12345
I just realised that this forum doesn't have an easy access for things that other people have coded. I don't mean games, levels or demos, more like hard functions to code, eg rts system functions and shop codes. So this is a topic for people to easily access some functions that they can edit for their needs. (If any moderators see this and don't like it, at least make a real topic for it similar to tutorials or game resources)

Rules
People can choose whether they want to be acknowledged when people use their function
You can enter functions in any form you want, eg just code, .ged, whatever
You must accept criticism if you enter a function BUT the criticism must be about how to make it work better, not work for something else
If there is a code from tutorials that would fit into this category, you can add the function AND GIVE ALL CREDIT TO THE CREATOR
There can be similar codes, but not direct copies

I will try to enter some things into this soon-ish, but since I'm in another time zone to all of you, there probably wont be anything yet

PS: If there are no responses to this within a reasonable time, can one of the moderators please delete this

Re: Community functions

PostPosted: Tue May 27, 2014 12:29 am
by GEuser
This is a good idea. Maybe a subforum within the resources section (Code Resources? Community Scripts?)

A lot of the stuff that I put up on the site is functions anyway. Feel free to link to or copy/paste some of my functions. Might be a good idea to index them alphabetically by topic and creator (to encourage submissions and recognition within the gE community).

I think in order to convince the gE development team of the merits of creating a 'FORUM COMMUNITY FUNCTIONS' section you'll need to create the content here first to prove it's of interest and that a demand exists. There's also the issue of proving it's your own work and not just blatant plagiarism.

You could index the functions already submitted on forums here (ask permission from original posters?). It would be a start. You have my permission either way. I'll try my best to put something here.

Come on people give this topic a fair chance and give some feedback.

Re: Community functions

PostPosted: Tue May 27, 2014 8:52 am
by barney12345
Ok, sorry about the delay, I had some issues on the way

Re: Community functions

PostPosted: Tue May 27, 2014 9:22 am
by digiot
GEuser wrote:Come on people give this topic a fair chance and give some feedback.

I think, the problem is, that most of such functions are too special, so you
had to build your code around it, to benefit from it.
Only very basic functions can be used everythere, e.g. like bat78s getclone2
emulations.
Even a "simple" state method for actor animation can have dozens of variants.
And I have noticed, that some people, who have enhanced their skills, don't
like to publish their work anymore.
But, why not building such an archive, at least for showing some concrete examples.


Cheers !

Re: Community functions

PostPosted: Tue May 27, 2014 10:08 am
by barney12345
Some more

Re: Community functions

PostPosted: Tue May 27, 2014 12:08 pm
by digiot
@ barney12345:
I've taken a look into your geds:
In the Jump demo, funny, when you arrange the smilies a little, it's some
kind of working, jumping and sliding down.
The physics demo works out of the box, also jumping.
The other both are missing the tffs, they won't load.
So I missed your intention for this thread, I thought, you meant custom functions
for the Global Code, not the usage of the inbuild ones.

Nethertheless, nice contribution !

Re: Community functions

PostPosted: Tue May 27, 2014 5:59 pm
by GEuser
digiot wrote:
GEuser wrote:Come on people give this topic a fair chance and give some feedback.

I think, the problem is, that most of such functions are too special, so you
had to build your code around it, to benefit from it.
Only very basic functions can be used everythere, e.g. like bat78s getclone2
emulations.
Even a "simple" state method for actor animation can have dozens of variants.
And I have noticed, that some people, who have enhanced their skills, don't
like to publish their work anymore.
But, why not building such an archive, at least for showing some concrete examples.


Cheers !


Yes, simpliticity helps. However, more advanced functions allow you explore and go beyond your comfort zone, forcing you to improve yourself. Your right though simple ones will have much more applications and I'm gonna try to add some.

Perhaps people could make requests for the types of simple functions they want to see here? It would give contributors a focus on what to work on.

Re: Community functions

PostPosted: Tue May 27, 2014 6:00 pm
by GEuser
getChance ( percentage );

The percentage probability of an event occurring. 1=occurred, 0 = failed.

GLOBAL CODE
Code: Select all
int getChance(double percSuccess)
{
    int chance=0;
    double randNum=rand(100.0);
    double lowBand=percSuccess/2.0;
    double highBand=100.0-(percSuccess/2.0);
 
    if (percSuccess<0.0) { percSuccess=0.0; }
    if (percSuccess>100.0) { percSuccess=100.0; }
 
    if(((randNum>=0.0)&&(randNum<=lowBand))||((randNum>=highBand)&&(randNum<=100.0)))
    {
        chance=1;
    }
 
    return chance;
}


MORE INFO HERE: viewtopic.php?f=8&t=13346

Re: Community functions

PostPosted: Tue May 27, 2014 7:23 pm
by digiot
@GEuser :
I'm not against complex functions here, but it's much less work, to tailor some
complex functions for a complex program, then vice versa !
It would be a kind of reverse engineering...

If you have some deeper functions laying around, feel free, to offer them here !
Like you said, at least we all could learn from it !

Concerning your random control, well done !
But I'm an rnd-hater ! I'm only using it, when it doesn't matter, what comes out.
In the most cases, you don't really want to have pure randomness, rather you
need a kind of "moderated randomness", not only giving the low and high boundaries.

Cheers !

Re: Community functions

PostPosted: Tue May 27, 2014 9:34 pm
by GEuser
digiot wrote:@GEuser :
I'm not against complex functions here, but it's much less work, to tailor some
complex functions for a complex program, then vice versa !
It would be a kind of reverse engineering...

If you have some deeper functions laying around, feel free, to offer them here !
Like you said, at least we all could lern from it !

Concerning your random control, well done !
But I'm an rnd-hater ! I'm only using it, when it doesn't matter, what comes out.
In the most cases, you don't really want to have pure randomness, rather you
need a kind of "moderated randomness", not only giving the low and high boundaries.

Cheers !


I have a terrible habit of going over the top and overlooking simplier (more effficient) solutions first, hehe. There's a few lessons for me to learn right here. Make complex things out of simple things first and if all else fails explore more complex ones later. Hehe, thanks digiot!

Re: Community functions

PostPosted: Tue May 27, 2014 10:38 pm
by digiot
GEuser wrote:Make complex things out of simple things...

Like Go compared with Chess, KISS rules !

Re: Community functions

PostPosted: Wed Jun 04, 2014 1:15 am
by lcl
Here's a very simple and basic function that I made because I needed it in my game. This is a very global level function, and I think this should even be included in the built-in Game Editor functions, since it is really useful.

The function syntax is:

void screen_to_real(int * x, int * y)

What this function does is really similar to what functions screen_to_actor() and actor_to_screen() do.
You can give screen_to_real any screen coordinates, xmouse and ymouse for example, and it will convert them to "real" coordinates, e.g. coordinates relative to the Game Center (0, 0). After calling screen_to_real the coordinates you gave to the function will return the modified values, but only in that certain event, just like screen_to_actor and actor_to_screen.

Here is the function code:
Code: Select all
void screen_to_real(int * x, int * y)
{
    *x = view.x + *x;
    *y = view.y + *y;
}

And here's an example of how to call it:
Code: Select all
screen_to_real(&xmouse, &ymouse);

The reason why you have to add the ampersand (&) before the variables is that the function needs the pointer to the variable data in memory so that it can edit that data. Without the ampersand you'd just pass the value of the variable to the function, and Game Editor would give you an error message because the function requires the values to be pointers to integers variables, not the values of the variables.

Here is also a small demonstration of the function in use:
screenToRealExample.zip
Download the example ged from here
(423.05 KiB) Downloaded 182 times

Re: Community functions

PostPosted: Mon Jun 09, 2014 1:24 pm
by digiot
Handy one, and nice demo !
lcl wrote:...This is a very global level function, and I think this should even be
included in the built-in Game Editor functions,...

Yes, you should also put it on the "Feature Requests" forum.
Maybe, they just forgot to implement it...

As simple it might look, I have 2 questions :

Am I right, x[0] is equivalent to *x ?

And...
Code: Select all
{
glob_x = view.x + xmouse;
glob_y = view.y + ymouse;

MoveTo("moveMeToClickPosition", glob_x, glob_y, 5.000000, "Game Center", "");
}

... would also work ?

Sure, inside a function, you have to use references, to change anything outside
of it. But is there any benefit, using the one or the other code ?


Cheers !

Re: Community functions

PostPosted: Mon Jun 09, 2014 2:18 pm
by lcl
digiot wrote:Am I right, x[0] is equivalent to *x ?

Yes. And I just updated the function to use *x instead. For some odd reason, I wasn't familiar with the practice of using * to get the value pointed to by the pointer, and because of that, came up with a workaround utilizing [0]. Good thing is that now I know one more thing again. Sorry if I caused confusion.

digiot wrote:And...
Code: Select all
{
glob_x = view.x + xmouse;
glob_y = view.y + ymouse;

MoveTo("moveMeToClickPosition", glob_x, glob_y, 5.000000, "Game Center", "");
}

... would also work ?

Yes, that would work.

digiot wrote:But is there any benefit, using the one or the other code ?

Well, there is the benefit of that it allows you to convert screen coordinates to real coordinates the same way screen_to_actor and actor_to_screen convert coordinates between different coordinate systems. If one is used to using screen_to_actor, or actor_to_screen, this will be convenient to use.

Re: Community functions

PostPosted: Fri Jun 13, 2014 10:40 am
by digiot
@lcl :
Arrays and pointers are so similar, you can even mix their notations !
I stumbled over this little table, though it is about the "Pointer Sisters"(**),
it does clearify the relation of the pointer- and the array-notation :
Code: Select all
Äquivalenz zwischen Zeigern auf Zeiger und mehrdim. Arrays
(Equivalence between pointers to pointers and multidim. arrays)

Zugriff auf …          Möglichkeit 1      Möglichkeit 2     Möglichkeit 3
(Access to ...         Option 1           Option 2          Option 3)
---------------------------------------------------------------------------
1. Zeile, 1. Spalte  | **matrix           *matrix[0]        matrix[0][0]
i. Zeile, 1. Spalte  | **(matrix+i)       *matrix[i]        matrix[i][0]
1. Zeile, i. Spalte  | *(*matrix+i)       *(matrix[0]+i)    matrix[0][i]
i. Zeile, j. Spalte  | *(*(matrix+i)+j)   *(matrix[i]+j)    matrix[i][j]
  (Row    ,  Column) |

Your example with xmouse/ymouse might cause some error, or are you sure, the
xmouse/ymouse variables can't get updated, while you are (ab)using them ?
The examples screen_to_actor and actor_to_screen are different, they are called
in any actor event, so the x/y variables don't get changed while you are
using them.
Or do I miss something here ?


Cheers !

P.s. : And a happy birthday, hope, it was the 12th, and not friday, the 13th !