setting private variable default values

For questions about using Classic.

Post » Fri Jul 01, 2011 6:46 am

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.
B
2
G
1
Posts: 8
Reputation: 466

Post » Fri Jul 01, 2011 8:39 am

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?
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Fri Jul 01, 2011 8:59 am

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. newt2011-07-01 09:00:02
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Jul 02, 2011 5:16 am

[QUOTE=alspal] 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?[/QUOTE]

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.

[QUOTE=newt] 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. [/QUOTE]

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
B
2
G
1
Posts: 8
Reputation: 466

Post » Sat Jul 02, 2011 6:23 am

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....
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Jul 02, 2011 12:20 pm

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 slowdownlucid2011-07-02 12:22:12
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests