setting private variable default values

This forum is currently in read-only mode.
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • This is an optimization issue.

    My game randoms generates weapons, like in borderlands, but each weapon has much more attributes than just "Damage", "Accuracy", and "Fire Rate", for visual effect and diversity. I currently have twenty two attributes, and for each attribute, the value must be written to the bullet in a private variable for every time a bullet is fired. And as you can imagine, if the weapon is a quickly shooting, multiple shot weapon, it causes quite a bit of lag when firing because for each bullet created it must have 22 values written to it.

    My question: is there any way that you can reassign the default values of a private variable? That way I would be able to make the values only be assigned one time; when you switch weapons. Then every bullet would already have the appropriate values for their private variables when they are created, and would not need to be assigned 22 new ones.

    Any help would be much appreciated.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Setting 22 values in an event doesn't sound like it would cause lag, how many bullets do you need to make per tick? Maybe you need to optimise other parts of your code?

  • Once a pv is changed in a layout there's no way to remember what its original value was.

    What you could do is use global variables, or better yet the hash, or ini object to store the original values.

    22 pv's is a lot to deal with all the time, you might consider a different approach by grouping variable types by common use.

    For example, an apple can have many different variables, red, green, sweet, tart, etc. But you dont just say I want a red apple, you call it by name IE Red Delicious, or Granny Smith.

    Now to use that in say something like an ini you would name a bullet as an ini group, and then if the bullets name/ group is used you can get its variables using for each item in group.

  • Setting 22 values in an event doesn't sound like it would cause lag, how many bullets do you need to make per tick? Maybe you need to optimise other parts of your code?

    it doesn't cause much lag if i'm using a simple weapon such as a pistol or a rifle, but if i use a rapid fire multiple shot weapon, it might have to assign 4 * 22 PVs every other other frame, which does build up and cause lag.

    Once a pv is changed in a layout there's no way to remember what its original value was.

    What you could do is use global variables, or better yet the hash, or ini object to store the original values.

    22 pv's is a lot to deal with all the time, you might consider a different approach by grouping variable types by common use.

    For example, an apple can have many different variables, red, green, sweet, tart, etc. But you dont just say I want a red apple, you call it by name IE Red Delicious, or Granny Smith.

    Now to use that in say something like an ini you would name a bullet as an ini group, and then if the bullets name/ group is used you can get its variables using for each item in group.

    I'm not trying to reset each PV to its original value, but rather trying to change the value that the PV starts as when the object containing the PV is created, I'm just wondering if there is a way I could do this because I already have all the PVs created and etc. It would just be annoying to start my whole weapon system over and use .ini files. Although it is an absolutely genius idea and I would have never thought of it, not to mention I'm trying to use mainly outside files for in-game content such as maps, animations, etc. And If I used your .ini file weapon system idea I could potentially save previously generated weapons for future reference which I guess would be nice.

    Thanks for the help! :D

  • One other thing to keep in mind. The naming system could also be applied against enemy's. Like a certain named bullet will do this much damage to one enemy type and different to another enemy type. In other words you wouldn't need to calculate all the variables each time. You can just add up all the variables beforehand and apply that instead.

    But then again 22 variables means a lot of permutations....

  • I don't know, this runs at just under 140 fps on my pc, and it's 25 sprites with 25 pvs each, with each pv of each sprite randomly changing each tick, and all 25 pv's of each sprite accessed each tick.

    i'm pretty sure there's something else causing the slowdown

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