App hangs on splashscreen while rendering elements

Hello,

I am new to Roku Channel development, and I am trying to build a starter channel that renders elements in and out.

I’ve included all the elements in the SceneGraph file, and initialized the proper elements through ids, but the channel now hangs at the splashscreen, and I’m not sure why.

Is this a scope issue, or something else entirely?

Any help would be appreciated.

Code:

main.brs

sub Main()
    showChannelSGScreen()
end sub

sub showChannelSGScreen()
    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    screen.setMessagePort(m.port)
    scene = screen.CreateScene("MainScene")
    screen.show()

    while(true)
        msg = wait(0, m.port)
    msgType = type(msg)
        if msgType = "roSGScreenEvent"
            if msg.isScreenClosed() then return
        end if
    end while
end sub

MainScene.xml

<?xml version="1.0" encoding="UTF-8"?>


<component name="MainScene" extends="Scene" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
	<!-- importing main handler -->
    <script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
    
    <children>
    
        <Label id="tempo" translation="[550, 50]" text="140" horizAlign="center" width="800" height="100" color="0xffffffff" font="font:LargeSystemFont"/>
        
        <ButtonGroup id = "metronomeButtons" />

        <PinPad 
            id = "pinPad" 
            pinLength = "3"
            secureMode = "false" />

        <SoundEffect
            id = "click"
            uri="pkg:/sounds/click.mp3"
            control="stop"
        />   
        
    </children>
</component>

MainScene.brs

sub initPinPad()
    metronomeButtons.visible = false
    pinPad.visible = true
    pinrect = pinPad.boundingRect()
    pcenterx = (screenwidth - pinrect.width) / 2
    pcentery = (screenheight - pinrect.height) / 2
    pinPad.translation = [ pcenterx, pcentery ]

    pinPad.setFocus(true)

end sub

sub initMetButtons()
    pinPad.visible = false
    metronomeButtons.visible = true

    rect = metronomeButtons.boundingRect()
    centerx = (screenwidth - rect.width) / 2
    centery = (screenheight - rect.height) / 2
    metronomeButtons.translation = [ centerx, centery ]

    metronomeButtons.setFocus(true)

end sub

sub init()
    m.top.setFocus(true)
    m.top.backgroundUri = ""
    m.top.backgroundColor = "0x80000000"
    
    click = m.top.findNode("click")
    tempo = m.top.findNode("tempo")
    pinPad = m.top.findNode("pinPad")

    screenwidth = m.top.width
    screenheight = m.top.height

    pinPad.visible = false

    metronomeButtons = m.top.findNode("metronomeButtons")

    metronomeButtons.buttons = [ "-", "Start/Stop", "+", "Keyboard" ]

    initMetButtons()

End sub

function onKeyEvent(key as String, press as Boolean) as Boolean
    result = true
    
    if press then
        if key = "OK"
            if click.state <> "playing"
                click.control = "play"
            end if
        end if
    end if
    
    return result 
end function

Welcome 867homely!

You have several problems. Are you connecting via telnet to port 8085 to see the debug output? If you were, you should see that it’s crashing on the pinpad.visible = true statement. That’s because pinpad isn’t defined. In your init function, you should use m.pinpad = m.top.findNode(“pinPad”) and then use m.pinpad everywhere. It’s the same thing with metronomeButtons.

Once you fix those things, you’ll find that screenheight and screenwidth aren’t defined. That’s because m.top doesn’t have a .width or .height property.

Use the debug console and work through the problems it displays one by one.

Sorry about that. I didn’t know about the debug output, I will go ahead and fix those issues.