Logo

[Help] How AddInputCallback() works??

Register Log In Back To Forums

Post #1 · Posted at 2015-01-10 04:29:16pm 9.2 years ago

Offline Th3_Ov3rHell_3XoduZ
Th3_Ov3rHell_3XoduZ Avatar Member
313 Posts
Chile
Reg. 2012-09-13

"ITG, The Best Dance Machine!"
Hello again... sorry for multiples topics but... I was taking a break about theming these days but now Im working again in a next Upodate of my Theme Metro Quad...

I was reading on http://kki.ajworld.net/lua/sm5/Lua.xml about codes and commands, etc... and I found that one AddInputCallback(). About what I read, I can call a function depending of differents values or determinates actions... for example pressing a determinate key or with multiples settings...

Anyway I tried to experiment with this one but I cannt get something works, I would like to know if someone has used this command and let me know whats things I can do with it...

My idea is execute some scripts using some combo-keys... I have so many ideas on my mind but I need a little help to start with this command.

Anyway Thanks for the help... It's very helpful Big Grin
Quote: Released Themes for SM5 Beta 3
Quote: Released Themes for SM5 Beta 4 & 5.0.7
Quote: Simfles Packs Released

Post #2 · Posted at 2015-01-10 06:23:12pm 9.2 years ago

Offline Kyzentun
Kyzentun Avatar Member
3,209 Posts
United States
Reg. 2008-02-20

"I'm honestly pissed off."

Last updated: 2015-01-10 06:23pm
http://codepad.org/GFrM9BN4

(SetStateProperties is a function I added last night, but that's not really relevant. I just didn't feel like taking an extra minute to make a demo that just changes a bitmaptext when I already had a similar enough demo.)

Basically, you write a function, call AddInputCallback and pass in that function. Then whenever input occurs, your function is called with the event structure filled out.
silenttype01: Kyzentun is never harsh. He says it how it is.

GENERATION 24: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

Post #3 · Posted at 2015-01-10 07:10:20pm 9.2 years ago

Offline Th3_Ov3rHell_3XoduZ
Th3_Ov3rHell_3XoduZ Avatar Member
313 Posts
Chile
Reg. 2012-09-13

"ITG, The Best Dance Machine!"
Quote: Kyzentun
http://codepad.org/GFrM9BN4

(SetStateProperties is a function I added last night, but that's not really relevant. I just didn't feel like taking an extra minute to make a demo that just changes a bitmaptext when I already had a similar enough demo.)

Basically, you write a function, call AddInputCallback and pass in that function. Then whenever input occurs, your function is called with the event structure filled out.

Well it is a little hard to understand at least for me... for example, I wanna try something very simple... on ScreenEvaluation i put this:

Quote
local Text

local function input(event)
if event.type == "InputEventType_Release" then return false end
if event.DeviceInput.button == "DeviceButton_w" then
Text = "Pressed W"
end
end

local Example = {
OnCommand= function(self)
SCREENMAN:GetTopScreen():AddInputCallback(input)
end,
LoadFont("Common Normal")..{
Text="Not Pressed";
InitCommand=cmd(Center;zoom,1);
},
}

return Def.ActorFrame(Example)

My idea is simple, try to change the text from "Not Pressed" to for example at the moment to press W, it shows "Pressed W"... I still dont understand this...
Quote: Released Themes for SM5 Beta 3
Quote: Released Themes for SM5 Beta 4 & 5.0.7
Quote: Simfles Packs Released

Post #4 · Posted at 2015-01-10 07:20:53pm 9.2 years ago

Offline Kyzentun
Kyzentun Avatar Member
3,209 Posts
United States
Reg. 2008-02-20

"I'm honestly pissed off."
So, the problem in your example is that you're not changing something visible. You're just setting the variable named "Text" to the string "Pressed W". Your input callback is actually working perfectly.
To actually see a result, you have to do something to an actor on the screen.

Something like this:

local text= false

local function input(event)
if event.type == "InputEventType_Release" then return false end
if event.DeviceInput.button= "DeviceButton_w" then
text:settext("Pressed W"
end
end

return Def.ActorFrame{
Def.BitmapText{
Font="Common Normal", Text= "Not Pressed", InitCommand= function(self) text= self self:Center() end,
OnCommand= function(self) SCREENMAN:GetTopScreen():AddInputCallback(input) end,
}

Notice that the BitmapText actor sets the variable "text" to itself in its InitCommand. Code that executes after that occurs can then use the text variable to do things to the BitmapText, like change the text being displayed.
silenttype01: Kyzentun is never harsh. He says it how it is.

GENERATION 24: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

Post #5 · Posted at 2015-01-10 07:29:40pm 9.2 years ago

Offline Th3_Ov3rHell_3XoduZ
Th3_Ov3rHell_3XoduZ Avatar Member
313 Posts
Chile
Reg. 2012-09-13

"ITG, The Best Dance Machine!"
Quote: Kyzentun
So, the problem in your example is that you're not changing something visible. You're just setting the variable named "Text" to the string "Pressed W". Your input callback is actually working perfectly.
To actually see a result, you have to do something to an actor on the screen.

Something like this:

local text= false

local function input(event)
if event.type == "InputEventType_Release" then return false end
if event.DeviceInput.button= "DeviceButton_w" then
text:settext("Pressed W"
end
end

return Def.ActorFrame{
Def.BitmapText{
Font="Common Normal", Text= "Not Pressed", InitCommand= function(self) text= self self:Center() end,
OnCommand= function(self) SCREENMAN:GetTopScreen():AddInputCallback(input) end,
}

Notice that the BitmapText actor sets the variable "text" to itself in its InitCommand. Code that executes after that occurs can then use the text variable to do things to the BitmapText, like change the text being displayed.

Ok Im understanding this a little... well yeah the code works, If I press W it will change the Text and then show it on screen... well thanks, ill try to experimenting what more I can do with this...

Thanks you Kyzentun
Quote: Released Themes for SM5 Beta 3
Quote: Released Themes for SM5 Beta 4 & 5.0.7
Quote: Simfles Packs Released
Register Log In Back To Forums

0 User(s) Viewing This Thread (Past 15 Minutes)

©2006-2024 Zenius -I- vanisher.com -5th style- IIPrivacy Policy
Web Server: 5% · Database: 4% · Server Time: 2024-03-28 20:36:40
This page took 0.005 seconds to execute.
Theme: starlight · Language: englishuk
Reset Theme & Language