[Help] functions in gE

Game Editor comments and discussion.

[Help] functions in gE

Postby friedfish » Wed Aug 08, 2012 12:36 am

hey guys,

I have this problem in gE when I make my own functions. it's with me almost everytime i make a game on gE. I have a workaround solution for it but I want to know if someone else is experiencing this. I want to know if there are any other solutions or if this is my fault because I'm making a mistake or is it gE.

here's the problem. I'll give an example to be easily understood.

first I have 2 actors: player and baddie. player has movements and the baddie I have a simple chase code on the draw actor/script editor.
Code: Select all
// dist is double and is a global variable declared on the global editor and not on the user variables
dist = distance(x, y, player.x, player.y);

//get distance then chase
if(dist <= 200)
{
    //rotation so baddie will face where player is
    double b_angle = direction(x, y, player.x, player.y);
    animpos = (b_angle/360)*nframes;

    //velocity of the chase
    angle = direction(x, y, player.x, player.y);
    directional_velocity = 5;
}


I have this code on the draw actor of the baddie. and to optimize my code I thought that I will also be able to use this code not just on baddie's but maybe other actors so i made a function on the global code editor

Code: Select all
void chase()
{
    // dist is double and is a global variable declared on the global editor and not on the user variables
    dist = distance(x, y, player.x, player.y);

    //get distance then chase
    if(dist <= 200)
    {
        //rotation so baddie will face where player is
        double b_angle = direction(x, y, player.x, player.y);
        animpos = (b_angle/360)*nframes;

        //velocity of the chase
        angle = direction(x, y, player.x, player.y);
        directional_velocity = 5;
    }
}


I saved it. Tried it on game mode and it works. the baddie chases the player. The problem comes after this.

After trying it on game mode I saved and closed the ged. And when I opened it again and go to game mode the rotation works (where the baddie faces where the player is) but the the chase doesn't. The baddie only rotates on its position but it doesn't chase me.

My solution for this was to copy the whole code again and paste it on the baddie draw actor / game mode and it works then I just delete the code on the draw actor and replace it with the function and go to game mode and it works. it did not happen to me just this once but 2 or 3 times on my other games too. This solution works good but then everytime I open the ged to edit the game I need to do it all over again so that it works.

any idea why this is happening? am I making a mistake somewhere? or is it gE? if so please do let me know... +1 :) :D
User avatar
friedfish
 
Posts: 75
Joined: Wed Mar 14, 2012 2:31 pm
Location: UK
Score: 7 Give a positive score

Re: [Help] functions in gE

Postby skydereign » Wed Aug 08, 2012 8:33 am

That is a rather weird problem. Try putting a comment in the draw event that calls the function that has directional_velocity. I believe this might be due to this bug http://sourceforge.net/apps/trac/game-editor/ticket/40.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: [Help] functions in gE

Postby savvy » Wed Aug 08, 2012 9:28 am

I despise this bug -.- especially when you have a few hundred lines of code that it decides to just make not work suddenly!

savvy
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: [Help] functions in gE

Postby friedfish » Wed Aug 08, 2012 10:20 am

ah, so I was right... I looked into my other codes and noticed that directional_velocity is the one causing problems... maybe the developers can look through the source code because at least, I think we know where the problem is now. something is happening to the directional_velocity(As a global variable) when you close the editor that you need to redeclare it again as an actor variable before it can work. So maybe they can start checking there

referencing directional_velocity works fine and all but how does the commenting work though? is it on the source code that when you comment directional_velocity then it is referenced as global? are there any other variables that does this?

And thank you Sky... +1... :D
User avatar
friedfish
 
Posts: 75
Joined: Wed Mar 14, 2012 2:31 pm
Location: UK
Score: 7 Give a positive score

Re: [Help] functions in gE

Postby skydereign » Wed Aug 08, 2012 7:16 pm

The problem has definitely been reported, as the ticket suggests. We are shorthanded in terms of developers though, so a lot of the bugs that we know gE has, haven't been fixed, and aren't scheduled to be anytime soon. This one might actually be a pretty easy fix, since directional_velocity is the only variable that does this. So, I'll take a look to see if I can fix it.

A similar problem exists in global code when changing an actor variable of another actor.
Code: Select all
void
blue ()
{
    actor.r=actor.g=0;
    actor.b=255;
}

Just calling this function (assuming it isn't actor's event) will not turn the actor blue. You need some reference to the actor before gE knows to update the variables. I've been told this is due to efficiency problems (actor variables would otherwise make gE really slow). So what gE does is read through the script event, and determine what actors have been referenced (by searching the text for their names). Any actor that has been referenced is likely to change its variables, and therefore added to the update list. This however doesn't read through global code.

I have suggested a few ways to fix this problem so that people wouldn't notice it, but makslane prefers to wait until we make a bigger switch to llvm (which would fix it and improve gE in many ways). For now though, no one is working on that.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest