Communication between 3ds Max Interactive and Scaleform Studio

The Scaleform Studio plug-in and the 3ds Max Interactive engine share a common Lua virtual machine, which means that Lua code run by Scaleform Studio (when running integrated with 3ds Max Interactive) can invoke Lua commands from 3ds Max Interactive, and that 3ds Max Interactive can invoke Lua commands from Scaleform Studio.

If you want your Scaleform Studio project to run in the stand-alone Scaleform Studio Player, we recommend that most communication between 3ds Max Interactive and Scaleform Studio be handled using the scaleform.Stage.dispatch_event and custom event listeners in the Scaleform Studio and 3ds Max Interactive Lua scripts.

The Scaleform Studio plug-in also provides scaleform.Stingray.send_message for sending events like mouse, keyboard, touch events from 3ds Max Interactive to Scaleform Studio.

Note: Calling 3ds Max Interactive functions within Scaleform Studio Lua scripts prevents the Scaleform Studio project from running in stand-alone mode.

Example: Sending mouse input to Scaleform Studio from 3ds Max Interactive

    --Send Mouse Cursor motion and Left Button Down and Up events.
    scaleform.Stingray.send_message("mouse_move" ,
        stingray.Mouse.axis(stingray.Mouse.axis_index("cursor"), stingray.Mouse.RAW, 3).x,
        stingray.Mouse.axis(stingray.Mouse.axis_index("cursor"), stingray.Mouse.RAW, 3).y)

    --Left Mouse Button Down
    if(stingray.Mouse.pressed(stingray.Mouse.button_index("left"))) then
        scaleform.Stingray.send_message("mouse_down",
            stingray.Mouse.axis(stingray.Mouse.axis_index("cursor"), stingray.Mouse.RAW, 3).x,
         stingray.Mouse.axis(stingray.Mouse.axis_index("cursor"), stingray.Mouse.RAW, 3).y, 0)
    end

    --Left Mouse Button Up
    if(stingray.Mouse.released(stingray.Mouse.button_index("left"))) then
        scaleform.Stingray.send_message("mouse_up",
            stingray.Mouse.axis(stingray.Mouse.axis_index("cursor"), stingray.Mouse.RAW, 3).x,
            stingray.Mouse.axis(stingray.Mouse.axis_index("cursor"), stingray.Mouse.RAW, 3).y, 0)
    end

Example: Loading a Main Menu template using custom messages

From Lua scripts in your 3ds Max Interactive project, you can load a Scaleform Studio project and send custom events to the project.

    scaleform.Stingray.load_project("template_menu.s2dproj", "content/ui/template_menu")
    scaleform.Stage.dispatch_event( { eventId = scaleform.EventTypes.Custom, name = "set_title",
                                data = "Main Menu" } )
    scaleform.Stage.dispatch_event( { eventId = scaleform.EventTypes.Custom,
                                name = "add_menu_item",
                                data = { itemText="Basic Level",
                                         keyText=Appkit.Util.plat("1", "a", "1", "cross") } } )
    scaleform.Stage.dispatch_event( { eventId = scaleform.EventTypes.Custom,
                                name = "add_menu_item",
                                data = { itemText="Exit",
                                         keyText=Appkit.Util.plat("esc", "b", "esc", "circle")} } )

Example: Registering a Scaleform Studio custom Listener in 3ds Max Interactive

This listens for all custom events and processes them using a provided function.

    customListener = scaleform.EventListener.create(customListener, MainMenu.on_custom_event)
    scaleform.EventListener.connect(customListener, scaleform.EventTypes.Custom)

This custom function listens for an event and record which menu button is pressed.

    MainMenu.action = nil
    function MainMenu.on_custom_event(evt)
        if evt.name == "button_pressed" then
            if evt.data.button_type == "menu_item" then
                MainMenu.action = evt.data.button_id
            end
        end
    end