Is there a way that one will be able to count input without manually counting it like the case I had with timer.delay?
What do you mean by “count input”? Count the number of times a key was pressed?
exactly
I tried searching in API reference but didnt get any luck
You need to do that yourself. Maybe:
function init(self)
self.action_count = {}
end
function on_input(self, action_id, action)
if action.pressed then
self.action_count[action_id] = (self.action_count[action_id] or 0) + 1
end
if self.action_count[hash("attack")] > 5 then
print("Rampage!")
end
end
oh thanks
It doesnt manage to call self.action_count
btw dont I need to use table.insert to put that data in this table/array(whatever its called in lua)?
I have another solution I will try it tommorow I feel so stupid asking this question
I wrote the code without testing. There were two issues: 1) I didn’t acquire input 2) The comparison did compare with nil and was outside the action.pressed check.
New version that has been tested:
function init(self)
msg.post(".", "acquire_input_focus")
self.action_count = {}
end
function on_input(self, action_id, action)
if action.pressed then
self.action_count[action_id] = (self.action_count[action_id] or 0) + 1
if self.action_count[hash("attack")] and self.action_count[hash("attack")] > 5 then
print("Rampage!")
end
end
end
May I ask why not use
function init(self)
msg.post(".", "acquire_input_focus")
self.action_count = 0
end
function on_input(self, action_id, action)
if action.pressed then
self.action_count = self.action_count + 1
if self.action_count > 5 then
print("Rampage!")
end
end
end
Björn’s example keeps track of the count for different action_id’s, in case that’s needed.
E.g. to distinguish between the “down” and “up” pressed counts.
i thought that was the case, thanks for clearing this out.