question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should Nu auto-select the first created screen?

See original GitHub issue

I am trying to make a Entity in the world. This is code:

module MyGame

open System
open Prime
open Nu
open Nu.Declarative

#if DEBUG
#nowarn "1182"
#endif

type MyUnitDispatcher () =
    inherit EntityDispatcher ()

    static member Properties =
        [define Entity.Depth 1.0f]
    
    override dispatcher.Register (entity: Entity, world) =
        Log.info "MyUnitDispatcher"
        
        let world = World.monitor (fun e world -> Log.info "update"; world) entity.UpdateEvent entity world 

        world

type MyLayerDispatcher () =
    inherit LayerDispatcher ()
    
    static member Properties =
        [define Layer.Name "Layer"
         define Layer.Persistent true]
  
    override this.Register(layer, world) =
        Log.info "MyLayerDispatcher"
        
        let entity, world = World.createEntity<MyUnitDispatcher> (Some "entity name") DefaultOverlay layer world
        
        world
        
type MyScreenDispatcher () =
    inherit ScreenDispatcher ()

    override this.Register(screen, world) =
        Log.info "MyScreenDispatcher"
        
        let layer, world = World.createLayer<MyLayerDispatcher> (Some "layer name") screen world
        
        world

type MyGameDispatcher () =
    inherit GameDispatcher ()
    
    override dispatcher.Register (_, world) =
        Log.info "MyGameDispatcher"
        
        let screen, world = World.createScreen<MyScreenDispatcher> (Some "screen name") world

        world

// this is a plugin for the Nu game engine by which user-defined dispatchers, facets, and other
// sorts of types can be obtained by both your application and Gaia.
type MyGamePlugin () =
    inherit NuPlugin ()

    // make our game-specific game dispatcher...
    override this.MakeGameDispatchers () =
        [MyGameDispatcher () :> GameDispatcher]
        
    override this.MakeScreenDispatchers () =
        [MyScreenDispatcher () :> ScreenDispatcher]
        
    override this.MakeLayerDispatchers () =
        [MyLayerDispatcher () :> LayerDispatcher]
        
    override this.MakeEntityDispatchers () =
        [MyUnitDispatcher () :> EntityDispatcher]

    // specify the above game dispatcher to use
    override this.GetStandAloneGameDispatcherName () =
        typeof<MyGameDispatcher>.Name

Entity does not spawn, update event does not calls. Whats wrong?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bryaneddscommented, Jun 28, 2019

There’s no principled way to do this without creating yet another F# reach-around, so I’ll not make initial screen selection automatic after all in the low-level API.

1reaction
bryaneddscommented, Jun 26, 2019

It looks like you had three issues -

1 - You gave the Layer two different names. In one place you named it “layer name”, but in the Properties you named it “Layer”. You should never give a name to a dispatcher in the Properties declaration as it will make all instances have the same name, something which Nu can’t allow since each simulant’s address must be unique.

2 - You forgot to select the screen you created. In order for Nu to show the contents of a screen, that screen must be selected.

3 - You create a vanilla entity with EntityDispatcher that would not render anything even if the screen was selected. I suggest something like BlockDispatcher if you’re just trying to get something on screen.

Here is the code with the fixes applied -

    type MyUnitDispatcher () =
        inherit BlockDispatcher ()

        static member Properties =
            [define Entity.Depth 1.0f]
    
        override dispatcher.Register (entity: Entity, world) =
            Log.info "MyUnitDispatcher"
            let world = World.monitor (fun _ world -> Log.info "update"; world) entity.UpdateEvent entity world 
            world

    type MyLayerDispatcher () =
        inherit LayerDispatcher ()
    
        static member Properties =
            [define Layer.Persistent true]
  
        override this.Register(layer, world) =
            Log.info "MyLayerDispatcher"
            let _, world = World.createEntity<MyUnitDispatcher> (Some "entity name") DefaultOverlay layer world
            world
        
    type MyScreenDispatcher () =
        inherit ScreenDispatcher ()

        override this.Register(screen, world) =
            Log.info "MyScreenDispatcher"
            let _, world = World.createLayer<MyLayerDispatcher> (Some "layer name") screen world
            world

    type MyGameDispatcher () =
        inherit GameDispatcher ()
    
        override dispatcher.Register (_, world) =
            Log.info "MyGameDispatcher"
            let screen, world = World.createScreen<MyScreenDispatcher> (Some "screen name") world
            let world = World.selectScreen screen world
            world

Lastly, do note that you’re using Nu’s low-level interface which has recently been subsumed by the Elmish interface here -

https://github.com/bryanedds/Nu/blob/master/Projects/Nelmish/Nelmish.fs

This high-level interface will take care of simulant creation and screen selection automatically so you don’t run into such problems!

Let me know if you have any more issues!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I auto-select the first item in a gallery?
Is there any way to 'Select.Parent' of the top item in a gallery when another screen is OnVisible (or the app on-start, even)?...
Read more >
How to auto select the first element with ng-repeat in ...
Thanks man for your response, yes I want it to auto select the first item that display after the user searches and also...
Read more >
Power Apps UI Tip : Auto Select an Item in a Gallery - YouTube
In this video, Brian shows you how to auto select an item in a gallery in Power Apps. This can be used for...
Read more >
Idea: Auto select the first value in a quick filter
I would like the ability to make quick filters more dynamic by automatically selecting the first value in the list. I can see...
Read more >
Best practices for the accessibility of an autocompletion ...
First, upstream audits are carried out on several components by an accessibility expert in order to ensure an initial selection.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found