FelipeCaners's Recent Forum Activity

  • It worked perfectly. Thank you a lot!

  • I'm planning to make a game of evolution based on natural selection. To test some things, I created a test project and created some basic forms of AI.

    In the project, I created a sprite called 'npc' which has a variable called 'food' that, in turn, is decremented by 1 over the frames. I created also another sprite called 'food' that serves as food, as its name suggests.

    The variable 'food' of the sprite 'npc' is initialized with 200 and, when it is less than or equal to 50, the NPC should go after food. For this functionality, I applied the behavior 'RTS' to make things easier. For a more realistic behavior, I made this food (for which the npc should seek) to be as close as possible. For this, I tried to use the "Pick closest", but somehow is not working right.

    The problem is that when the npcs "get hungry", they always go after the same food, i.e., they do not go after the food closer to them.

    (I can freely create npcs and foods by pressing the left or right mouse buttons.)

    Here is my event sheet:

    + System: Start of layout

       -> npc: Destroy

       -> food: Destroy

    + MouseKeyboard: On Left mouse button Clicked

       -> System: Create object npc on layer 1 at (MouseX, MouseY)

    + MouseKeyboard: On Right mouse button Clicked

       -> System: Create object food on layer 1 at (MouseX, MouseY)

    + System: Always (every tick)

       -> npc: Subtract 1 from 'food'

    + npc: Value 'food' Less or equal 50

       + food: Pick closest to: npc.X, npc.Y

          -> npc: Add waypoint at food

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh, it works pretty fine now. Thank you, guys. ;)

  • Well, it worked well, but only when I create one object CParticle. If I create another objects CParticle, only the last one is updated. I think Construct only takes the lost picked "spr" in count.

    How am I supposed to fix this? I've tried to use SOL.spr[index] but I get the same "IndexError" as before.

    My code so far is on the .cap:

    particle.cap

  • Oh, it now works! Thank you a lot ^^

  • Hi everyone. I'm new to the forum so.. hello! My name is Felipe and I use Construct for a while making my game experiments.

    Anyway.. My real purpose of registering in the forum is to solve a annoying problem I've been having:

    Although I know that there's a particle effect built-in in Construct, I'm trying to create my own Python-scripted one.

    Here is the CParticle class:

    class CParticle:

         ID = 0;

         def __init__( self, nX, nY, nW, nH ):

              CParticle.ID += 1;

              self.ID = CParticle.ID;

              self.nX = nX;

              self.nY = nY;

              self.nW = nW;

              self.nH = nH;

              self.Create();

         def Create( self ):

              System.CreateByName( "spr", 1, self.nX, self.nY );

              spr[self.ID].Width = self.nW;

              spr[self.ID].Height = self.nH;

    And this is my second script that creates a CParticle instance:

    particle = CParticle( 200, 200, 8, 8 );

    My problem is that when I run the project, I get the following error message:

    Traceback (most recent call last):

    File "<string>", line 1, in <module>

    File "<string>", line 11, int __init__

    File "<string>", line 15, in Create

    File "<string>", line 482 in __getitem__

    IndexError

    Okay, I see that the index in "spr[self.ID]" (suposed to be 1] doesn't exist, but the sprite is created on screen. I tried to replace self.ID for 1 (since there's already another instance before the creation) and I get the same error.

    So, my question is: why Construct does not detect the new instance?

FelipeCaners's avatar

FelipeCaners

Member since 28 Jan, 2012

None one is following FelipeCaners yet!

Trophy Case

  • 12-Year Club

Progress

12/44
How to earn trophies