Function parameter limit?

This forum is currently in read-only mode.
  • Could you possibly just give me an example of how I'd through a function create a sprite and then instantly set its variables, though?

    Construct is pretty picky about defining variables in the same event, or sub-events, of where you created the sprite...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can create objects like this

    System.CreateByName("<sprite's\object's name", layer_num, x pos, y pos)

    after that you can set it's variables like this

    SOL.<sprite's\object's name>.SetValue('<value's name>', <the value>)

    SOL stands for selected objects list, it picks the last created object in this case.

    So your python function should look like this:

    def create_sprite(layer, x, y, var1, var2):

         System.Create("Sprite", layer, x, y)

         SOL.Sprite.SetValue('a', var1)

         SOL.Sprite.SetValue('b', var2)

    etc

    and if you want to call it just insert this line under an event

    create_sprite() - and fill the values of course.

    You can set default values, so if you mostly use a specific layer, variables, etc, than you don't have to specify them over and over, just rewrite the original function like this

    def create_sprite(layer = 1, x = 0, y = 0, var1 = 40, var2 = 20)

    In this way you can spawn another instances by typing just create_sprite().

  • Thanks for that!

    Just a question though, is Python not any good at all for every tick? Because this seemingly simple code I tried to make completely devestates my game's FPS in Unlimited. The actual code is 8 lines and dropped 900 FPS to 800, then I copied it to make up 118 lines and it's down to 200.

    Am I just missing something? Thread's a bit derailed I guess!

  • sorry, my mistake, you only need to define the function at start, after that you shouldnt have any performance issues.

  • Well, with a defined function for it instead it still runs awful (this is me trying to replace some events, not make effects), but I'm thinking that maybe you can't really test performance of Python in that way in Unlimited? Like it will be far too demanding to reference that code so fast, but in normal speeds it's perfectly fine?

    Hard to explain.

  • As far as I know, in most of the cases the events and python are running at the same speed, because both of them calling functions that were written in c++(like the system object's "create" function, or the sprite object's "setvalue".)

    I think you probably calling the python functions too often, that may lead to performance issues.

    Post the cap, or at least a shot of it, I can't help you without knowing the exact problem.

  • Well I call it every tick. I really wouldn't expect it to be this slow. This is basically the code I did that, if run "every tick", creates a noticable drop in testing FPS:

    Sprite.AddValue('value',500*System.TimeDelta)

    if Sprite.Value('value') >= 270:

    Sprite.AddValue('value',500*System.TimeDelta)

    if Sprite.Value('value') >= 360:

    Sprite.SubValue('value',360)

    It's a variable used for sine motions, if you're wondering why 360, etc. There's only one instance of the sprite being referenced, too.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)