Page 1 of 1

Issue with creating timers in the script editor

PostPosted: Sat Mar 15, 2014 9:30 pm
by CrackedP0t
So, I have this code in the Global Code:
Code: Select all
struct {
    struct {
        int xoffset;
        int y;
        int wait;
        int end;
           } movements[5];
    int columns;
    int waittime;
    int enemytype;
    int rows;
    int untilnext;
       } levels[5][5];

oid startsquad(int levelno, int squadno) {
    Actor * view = getclone("view");
    int c;
    Actor * enemy;
    int offint;
    int r;
    for (c = 0; c < levels[levelno][squadno].columns; c++) {
         offint = view->width / (levels[levelno][squadno].columns + 1);
         for (r = 0; r < levels[levelno][squadno].rows; r++) {
             enemy = CreateActor("enemy", "enemy0", "(none)", "(none)", view->x + offint * (c+1),
              levels[levelno][squadno].movements[0].y, true);
              CreateTimer(enemy->clonename, "linetimer", levels[levelno][squadno].movements[0].wait * r);
                                                             }
                                                             }
                                            }

I call startsquad(0,0) in an actor.
It mostly works, but the timer's not working when I create it from the function. It works fine when I create it otherwise.
Please help

Re: Issue with creating timers in the script editor

PostPosted: Sun Mar 16, 2014 3:45 pm
by lcl
It's kinda hard to try to solve your problem without having it in a .ged, and it's quite difficult to make one since all the actor names and animations and timer names should match. Could you make an example .ged with only this thing in case you don't want to share your entire project with everyone? :)

Re: Issue with creating timers in the script editor

PostPosted: Sun Mar 16, 2014 4:08 pm
by CrackedP0t
Nah,I'll just post the whole thing. I'm not worried about it.

Re: Issue with creating timers in the script editor

PostPosted: Sun Mar 16, 2014 6:44 pm
by lcl
The problem is that the CreateTimer -function tries to create a timer that doesn't exist in the project.

It appears that new timers created while in the Global Code (not created like in Game Mode, but created as added to the game project via the Create Timer -menu) are not usable anywhere - you can't add events to them, Game Editor doesn't add the whole timer to the project.
Changing the name of the timer to be created to shottimer, which you already have created in the player actor's Create Actor event fixes it.
But you won't be able to see it working before adding some event to the timer, which you hadn't done.

I added this to the enemy actors timer event for shottimer:
Code: Select all
r = g = 0;

And it changes color after a while.

Re: Issue with creating timers in the script editor

PostPosted: Sun Mar 16, 2014 9:29 pm
by CrackedP0t
Thanks. However, I need the shottimer for something else... how can I use linetimer?

Re: Issue with creating timers in the script editor

PostPosted: Sun Mar 16, 2014 9:41 pm
by lcl
CrackedP0t wrote:Thanks. However, I need the shottimer for something else... how can I use linetimer?

What's the problem with using shottimer? Really the only difference is the name, aince you modify its length anyway. Different actors can use the same timer for different things.

Re: Issue with creating timers in the script editor

PostPosted: Sun Mar 16, 2014 10:20 pm
by CrackedP0t
The shottimer shoots periodically and constantly. The linetimer will be used to make them move forward in a line.

Re: Issue with creating timers in the script editor

PostPosted: Sun Mar 16, 2014 10:26 pm
by lcl
Well, then you just have to have the timer in some actor, defined in an event, not Global Code.
For example, you can create an actor called timer actor. Put the timer in its create actor and destroy the actor in the timer event. It's an ugly fix but should allow you to use the timer everywhere on the project, even in Global Code.

Re: Issue with creating timers in the script editor

PostPosted: Mon Mar 17, 2014 7:00 pm
by CrackedP0t
OK; I tried to use a timer actor, but it didn't work.
Could you please add it to the GED and post it?
:)

Re: Issue with creating timers in the script editor

PostPosted: Mon Mar 17, 2014 7:30 pm
by lcl
CrackedP0t wrote:OK; I tried to use a timer actor, but it didn't work.
Could you please add it to the GED and post it?
:)

How did you try it?
You have to first define the timer in the timer actors event.
I can add it but not today. I'll send it to you tomorrow if you don't get it fixed by that time.

Re: Issue with creating timers in the script editor

PostPosted: Thu Mar 20, 2014 2:26 am
by CrackedP0t
OK, I need that GED; maybe it's just a bug.

Re: Issue with creating timers in the script editor

PostPosted: Thu Mar 20, 2014 3:11 am
by lcl
CrackedP0t wrote:OK, I need that GED; maybe it's just a bug.

Yes, it is a bug, as I said. I did some testing, and it appears that if a timer is not a part of any actor's event (and using a timer through another function doesn't count)
as a CreateTimer() call or as the selected timer for the timer event, it will disappear from the project.

So, for adding a timer that will be only created through a function defined in the Global Code, there's one way you can do it.

Go to any actor's any event (for example view's create actor event), and first define the timer there by using a CreateTimer call.
Then go to Global Code and add your timer creation code to you function. Then give the timer event to the actor the timer will be created to
with that function. After that you can erase the CreateTimer call from the event you first defined the timer in, (this would mean view actor's create actor event in this example of mine).

So while you don't actually need a specified timer actor as I first suggested, you still need to first define the timer straight in an actor's event.

With this explanation you should be good even without me sending an example ged for you, but here's one anyway.

Re: Issue with creating timers in the script editor

PostPosted: Sat Mar 22, 2014 6:00 pm
by lcl
So did it work / did you understand it now? :)

Re: Issue with creating timers in the script editor

PostPosted: Sun Mar 23, 2014 12:01 am
by CrackedP0t
Yep. Thank you!