how do i create a button on scale form to play an animation

how do i create a button on scale form to play an animation

msgambelluri
Advocate Advocate
993 Views
7 Replies
Message 1 of 8

how do i create a button on scale form to play an animation

msgambelluri
Advocate
Advocate

I went thru the scaleform tutorials but I still cant figure out how to add a simple button to play an animation in scale form

User presses the button and an animation plays.

Its easy with flow nodes using a keyboard input? Why is it so difficult with scaleform and a button on the HUD?

any samples out there that dont require a pile of lua scripting?

could i "highjack" an existing template and start from there?
Thanks

 

Marcello Sgambelluri

EESignature

Reply
Reply
0 Likes
994 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

Its quite lengthy but I will attempt to explain, with the assumption you know your lua scripting

 

In the Character Template:

 

input_mapper.lua: Defines the keystroke. In this lua file you assign "input.whatever" a key or "input.whatever=Keyboard.pressed(Keyboard.button_id("i"))" in local function update_button_input(self, dt)

Also in this file,

function InputMapper:if_whatever()

  return self.input.whaterver

end

 

is the file that has access to the keyboard assignment.

 

 

 

player_hud.lua: Is the lua file that interfaces player to the Scaleform buttons, text, blah blah blah, which resides in Main,lua. In this file you create a function.

 

Example 

function updateToScaleform(myVar)
  local event = {
     eventId = scaleform.EventTypes.Custom,
     name = nil,
     data = nil,
  }

  event.name = "update_that_button"
  event.data = myVar

  if event.name and event.data then
    scaleform.Stage.dispatch_event(event) --Important reference function
  end
  print ("[player_hud.lua]: updateToScaleform")
end

 

The variable "event" is a table with two indices: 'event.name' and 'event.data'

event.name is the actor as define by Scaleform Editor while event.data is the whatever data you want to pass. In your case, instead of updating the Scaleform project, this is where you place your animation call.

 

The function updateToScaleform(myVar) is in association with this function as a means for player.lua to access.

function PlayerHud:check_whateverKey()
       return self.input.whatever
end

 

 

 

Main.lua: Lua file located in UI folder of your project, this file is the file that modifies the state of your Scaleform project during game time. When updateToScaleform(myVar) is called, its communicates to Main.lua to perform the update. Not required since you are doing animation call.

 

 

 

player.lua: Finally all tied to this file. 

 

local function check_whatever(self)

  local whatever = Appkit.input_mapper:if_whatever() or PlayerHud:check_whateverKey()

  if whatever then 

     updateToScaleform(myvar)

  end

end

 

the check_whatever(self) is waiting for a keyboard signal and it 

is lined in function Player:update(dt) to be checked during frame updates.

 

 

So to your question; yes, you can do lua scripting to get custom keystrokes.

 

Respectfully

 

Joseph

Reply
Reply
0 Likes
Message 3 of 8

Anonymous
Not applicable

Oops this was a keyboard example.

Reply
Reply
0 Likes
Message 4 of 8

msgambelluri
Advocate
Advocate

Thanks

i need a button on hud so it could be clicked in game to play an animation

 

 

 for keystroke its easy!!!!!!!! with flow nodes "playanimation flow node" and an "input" flow node two nodes... done....

a  scale form "button" to be clicked in game seems very complicated.

 

is there a way to do it? in a simple way?

if not what is the way to do it?

 

Thanks

 

Marcello Sgambelluri

EESignature

Reply
Reply
0 Likes
Message 5 of 8

Shanii2
Collaborator
Collaborator

lets break it down does your animation is in 3d world or on 2d Scaleform scene.?.  And whenever you create a widget it automatically creates a widget handler and widget script. for you. just to be a technical approach when you open the handler it actually responds to events to and from widget script hence either outgoing events or incoming events.  Once you create a button in scaleform scene, open its widget handler.  lookup for the function called clicked, and uncomment the code below it to make it executable.

) Then change the event name so that it is identifiable. 

) save the handler script of button make sure to rename your button actors and button handlers accordingly.

)You can test run the button and in the logs you'l see that button is invoking a call.

) In stingray there are few basic flow nodes under scaleform 

)first of all you need to register the scene and view so that the scaleform project and the scene will be loaded.

) then you have to register the scaleform's incoming events Using 'Scaleform>register event'. In here you simply write the Name of the event which you had changed in step 1 of the button handler, that way it'll recieve the call.

) Then you need to add 'Check event listener' to listen for the incoming events. Make sure that you invoke it every frame or at prior time so that it can catch the event, you only need to register the events once.

) In check event listener you again specify the Event name to check for that is the same name you've given to the register events, and in button handler, there's also a data payload to extract the data but for button you only interested in event execution.

) Then simply plug the Out event port of Check event listener to any other events or things you want to do such as play animation, open/close doors/ turn lights on / off. etc.

 

Reply
Reply
0 Likes
Message 6 of 8

msgambelluri
Advocate
Advocate
Hi thanks for that explanation

I tried what you are showing and I cant get it to work

but I am missing some steps I am sure


I admit I am new to scaleform but not new to flow nodes.

I want to play an animation of a construction sequence in my level

i want button to "play" the animation with a button on the "hud" so I need to trigger the "play animation" flow node from

a button added in scaleform


could I recommend that you show a video of stepbystep?

it will be easier to follow and I could then mark this as a solution

I did get the log to show "button clicked" but could not anything past that to work


fyi

I cant find any examples of connecting button widgets from scale form to

flow nodes using the "SCALE FORM FLOW NODES" so for now you are my only hope!

thanks

Marcello Sgambelluri

EESignature

Reply
Reply
0 Likes
Message 7 of 8

msgambelluri
Advocate
Advocate

Perhaps you could show an image of the level flow nodes?

 

Marcello Sgambelluri

EESignature

Reply
Reply
0 Likes
Message 8 of 8

Shanii2
Collaborator
Collaborator

I hope this video will brief about the process.

You just rename the event to appropriate name and target that to Registor Event and check Event listener function nodes.

Scaleform

Reply
Reply
0 Likes