Problem using Monarch with RenderCam (Using collection proxies with a camera)

I don’t like to ask questions about completely different libraries developed independently by 2 (fantastic) developers, but I’m really confused about this and I feel like the problem I’m having may lie in my misunderstanding of the way collections and collection proxies work.

OK, so here’s my basic setup. I have more folders but I’m only showing the 2 relevant folders, game and main. The game folder holds everything needed to run game.collection which is also located inside the game folder. The main folder contains folders for each collection with collection proxies and other stuff as well as a main script to navigate to a specific collection.

game (folder)
   |___ bullet
   |___ enemy
   |___ joystick 
    ^^^ (these folders contain respective game objects)
   |___ player
      |___ player.go
         |___ player_sprite
         |___ player_script
         |___ camera.script (reference to camera.script in rendercam folder)
         |___ bullet_factory
         |___ basic_collisionobject
   |___ game.collection
      |___ camera.go (reference to camera.go in rendercam folder)
      |___ game.go (contains factories for spawning some stuff as well as the GUI and some other stuff)
      |___ player.go (reference to player.go in player folder)
main (folder)
   |___ main.collection
      |___ main.go
         |___ main.script
      |___ game.go
         |___ game_collectionproxy (linking to game.collection)
         |___ screen.script (reference to screen.script in monarch folder)

That’s the basic setup. The two libraries I’m using are Monarch by @britzl and Rendercam by @ross.grams.

Here’s my problem -

When I have my bootstrap collection pointed to game.collection, everything is working perfectly. The game opens up in game.collection and game.script gets run. game.script calls rendercam.follow("player#player", false). This tells the camera to start following the player. The camera works as it should and there are no errors.

But I want to open in main.collection and then open game.collection from main.script. When I set up my bootstrap collection in game.project to be main.collection, main.script successfully opens game.collection but the input doesn’t seem to be working. (the 2 joysticks I have aren’t working) The on_input function never gets called when I click or drag. (all this worked fine before)

I get a bunch of errors -

ERROR:SCRIPT: /rendercam/rendercam.lua:239: ERROR - rendercam - NO ACTIVE CAMERA!
stack traceback:
	[C]: in function 'error'
	/rendercam/rendercam.lua:239: in function 'calculate_view'
	/rendercam/rendercam.render_script:31: in function </rendercam/rendercam.render_script:29>
ERROR:SCRIPT: /rendercam/rendercam.lua:239: ERROR - rendercam - NO ACTIVE CAMERA!
stack traceback:
	[C]: in function 'error'
	/rendercam/rendercam.lua:239: in function 'calculate_view'
	/rendercam/rendercam.render_script:31: in function </rendercam/rendercam.render_script:29>
ERROR:SCRIPT: /rendercam/rendercam.lua:239: ERROR - rendercam - NO ACTIVE CAMERA!
stack traceback:
	[C]: in function 'error'
	/rendercam/rendercam.lua:239: in function 'calculate_view'
	/rendercam/rendercam.render_script:31: in function </rendercam/rendercam.render_script:29>
ERROR:SCRIPT: /rendercam/rendercam.lua:239: ERROR - rendercam - NO ACTIVE CAMERA!
stack traceback:
	[C]: in function 'error'
	/rendercam/rendercam.lua:239: in function 'calculate_view'
	/rendercam/rendercam.render_script:31: in function </rendercam/rendercam.render_script:29>
ERROR:SCRIPT: /rendercam/rendercam.lua:239: ERROR - rendercam - NO ACTIVE CAMERA!
stack traceback:
	[C]: in function 'error'
	/rendercam/rendercam.lua:239: in function 'calculate_view'
	/rendercam/rendercam.render_script:31: in function </rendercam/rendercam.render_script:29>
ERROR:SCRIPT: /monarch/monarch.lua:364: /monarch/monarch.lua:156: Could not send message 'transition_show_in' from 'controller:/game#game_screen' to 'game:/go#game'.
stack traceback:
	[C]: in function 'assert'
	/monarch/monarch.lua:364: in function 'on_message'
	/monarch/screen.script:32: in function </monarch/screen.script:19>

So it seems the main problem is the first error - no camera found. Does the reference to camera.go need to be in main.collection? I tried doing this but it didn’t change anything. I’m not sure if the input problem is a separate problem or it has to do with the buggy code. I’m really confused and I would appreciate any help.

Thanks for reading this. Hope to hear somebody’s thoughts/suggestions.

I really need this camera/screen-transition bug fixed before I move on to adding pages for a shop and inventory. :worried:

Hey,
i think you need a camera in your Main collection too.
Just add a camera.go into your main collection, like you did it for your game collection.

2 Likes

Yep, nothing wrong with Monarch here, but at the moment Rendercam requires that you have an active camera at all times. Then I suspect the error from Rendercam is preventing your other code from running.

I plan to add a fallback for exactly this situation, but haven’t gotten around to it yet, sorry!

Another thing to clear up though: your file folders have nothing to do with how your game works. The hierarchies of game objects in your collections are totally unrelated to your file system. You can move files around however you want and your collection will still be the same.

1 Like

This is important knowledge about how Defold works and I feel like we’re sometimes doing a poor job of teaching it. Not sure how to make this more clear though…

2 Likes

OK, I updated RenderCam to use a fallback camera when no user cameras are active. Now you should just get one message on init, which you can ignore. Let me know if you have any issues with it.

3 Likes

In the docs have a list of the most common gotchas and misunderstandings. Then make it recommended reading in the onboarding.

Thank you all for your help. Thanks for updating Rendercam, @ross.grams. But I still have a problem…

So as per everyone’s suggestions, I added camera.go to main.collection in addition to the one already in game.collection. Unfortunately, I’m still getting an error… and it isn’t from Rendercam. It’s from the aforementioned Monarch library.

ERROR:SCRIPT: /monarch/monarch.lua:364: /monarch/monarch.lua:156: Could not send message 'transition_show_in' from 'controller:/game#game_screen' to 'game:/go#game'.
stack traceback:
	[C]: in function 'assert'
	/monarch/monarch.lua:364: in function 'on_message'
	/monarch/screen.script:32: in function </monarch/screen.script:19>

The only function I’m calling from main.script is the show function from monarch -
monarch.show(hash("game")).

game.collection does open up and game.script is running fine and all the GO’s are working perfectly. (I think) But input isn’t getting registered. Nothing in the on_input callback is getting called. (the update functions are working fine, though)

I am calling msg.post(".", "acquire_input_focus") in the init function in main.script and no where else. So I’m not sure why that error is showing up and I’m not sure why input isn’t working.

I would definitely appreciate help/suggestions/pointers.

Please share the project with me (bjorn.ritzl@king.com) and I’ll take a look.

Just sent the zipped project folder to you.

Ok, so there were a couple of issues, specifically around naming and urls. In the screen.script for the game screen you’ve specified that transition and focus messages should be handled by a script available on the game:/go#game URL (ie something inside the collection loaded by #game_collectionproxy):

BUT if we take a look at what’s inside the game.collection we see that there is no game object named go. Instead there’s a game object named game:

46

With the above layout in mind the correct transition and focus URL would be game:/game#game and not game:/go#game. There is however one more issue and that is the name of the game.collection itself. The collection is named main and not game as the URL implies:

46

You need to either rename the collection and the game object or change the transition and focus URLs to match the actual names. If you change nothing then the transition URL for the current setup is main:/game#game but it makes more sense to rename the collection to game.

OK. That makes sense. I will give this a try tommorrow morning and let you know if that clears all my problems. Thanks for your help!

It should. It worked without problems when I tried it at least :slight_smile:

I’m not getting any errors but I still have one last problem.

I renamed the collection and the game object and game.collection now opens properly from main.collection. However, input isn’t getting registered. Nothing in on_input in game.script is getting called.

I’m not sure why this is happening. I read this over here but I’m not sure what I’m doing wrong.

I’m pretty sure it has something to do with my placements of msg.post(".", "acquire_input_focus"). But I’m not sure where I’m going wrong. Sorry to keep bugging you with this @britzl. :slightly_frowning_face: I’m pretty new to Defold and I’m not yet familiar with everything in the API.

No worries. I’m visiting our Barcelona office for a Defold training and it’s been a couple of busy days so I haven’t had to to reply. The only place where you should have to do msg.post to acquire input focus is from your main/bootstrap collection where you have the proxies to your screens.

Perhaps if you share the project with me (bjorn.ritzl@king.com) and I can take a look as soon as I have time.

Thanks for your reply.

I am calling msg.post(".", "acquire_input_focus") in only 1 place - main.script. And I am able to detect input from on_input in main.script but I can’t detect input from game.script.

I did share the project with you. You pointed out that I didn’t name my main collection and game object correctly. Was the input working for you when you fixed it? (Those 2 circles w. dots at the bottom are virtual joysticks for the tank, by the way) Were you able to control the joysticks?
If you get some time to take another look at my project, I would really appreciate it. :slight_smile:

By the way here’s what I have in my main.collection -

   |___ main.collection
      |___ main.go
         |___ main.script
      |___ game.go
         |___ game_collectionproxy (linking to game.collection)
         |___ screen.script (reference to screen.script in monarch folder)

I have msg.post(".", "acquire_input_focus") in main.script. Isn’t that the only place it should be?

Where is game.script? If it’s in game.collection (via game_collectionproxy) then you also need to acquire input focus on game.go.

[Edit] See here in the manual.

1 Like

OK. I see. Makes sense. It is in game.collection. I’ll give that a try as soon as I can. Thanks! :slight_smile:

Yes! It’s finally working! All I did was acquire input in the main script for my game collection and acquire input in Monarch’s screen.script (which is a component of each of the game objects for each screen in main.collection; see above for full structure)

Don’t know if this is a good idea, @britzl, but maybe Monarch’s screen.script should by default acquire input. Just a suggestion. Maybe it’s not a good idea. But, thank you all so much for helping me fix this issue! Now I can finally move on to building the shop and inventory for my game. :grin:

1 Like