Basic question about state variables and programming technique

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
hamberge
Prole
Posts: 25
Joined: Wed Aug 16, 2017 2:55 pm

Basic question about state variables and programming technique

Post by hamberge »

I find myself creating new state variables for every facet of character activity that I implement. For instance every new micro feature that I add to character behavior gets a whole new set of state variables. In one example, i use separate animation timers for each character instance. Is this considered bad technique? I could imagine instead using some shared state (e.g., a shared or global timer for damage ticks or animation ticks) to cut down on the number of variables. Should I be trying to limit the number of new state variables? Am I worrying about optimization too prematurely?
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Basic question about state variables and programming technique

Post by Sir_Silver »

What does a state mean with regards to what you're talking about? Unique timers for each character instance sounds like a good thing, unless you want every character instance to start and stop all of their animations at the same time relative to each other. It's hard to tell you whether or not you're "doing anything wrong" or using any "bad techniques" without seeing your code, so I'll just say write your game and worry about optimization after, they say premature optimization is the root of all evil.
hamberge
Prole
Posts: 25
Joined: Wed Aug 16, 2017 2:55 pm

Re: Basic question about state variables and programming technique

Post by hamberge »

By state I'm referring to all variables that store information in between love.update() calls, whether it be "important" variables like screen position or position within a tile-based board, or helper variables that track movement progress. Other examples are Booleans for tracking movement, indices for tracking the progress through a pathfinder path, etc. This stuff is pretty much all stored in an instance of a "player" class for each character on the screen. The list of variables in the player class prototype keeps growing and I'm wondering if that is normal. Maybe it is...
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests