My select function breaks the panning function


#1

I have a map and I can select stuff to display stats for on the gui. The panning controls are in main and the gui controls are in the gui script. please help me find the issue I dont no where to start.game (2).zip (2.1 MB)


#2

So when you pan around on the map you can no longer select stuff on the map? Do you apply the offset of the map when you do picking on the map?

Camera extensions such as RenderCam and Defold-Orthographic has support for screen to world conversion.


#3

No when I select things I can no longer pan around the map. Selection already factors in conversions.


#4

The project gives me a couple of errors when I start it:

DEBUG:SCRIPT: table: 0x0d29e860
DEBUG:SCRIPT: nil	/Users/bjornritzl/Library/Application Support/laser/grid_data: No such file or directory
ERROR:SCRIPT: /assets/objects/map/map_script.script:9: attempt to index local 'f' (a nil value)
stack traceback:
	/assets/objects/map/map_script.script:9: in function 'update_grid_data'
	/assets/objects/map/map_script.script:43: in function </assets/objects/map/map_script.script:40>
DEBUG:SCRIPT: vmath.vector3(1, 1, 1)
DEBUG:SCRIPT: 250	250
DEBUG:SCRIPT: vmath.vector3(250, 250, 9.9999997473788e-05)
ERROR:SCRIPT: /assets/objects/player/player_script.script:26: attempt to index a nil value
stack traceback:
	/assets/objects/player/player_script.script:26: in function </assets/objects/player/player_script.script:14>
DEBUG:SCRIPT: Please Work
INFO:DLIB: SSDP: Started on address 172.19.50.101
INFO:DLIB: SSDP: Started on address 192.168.0.144
WARNING:DLIB: Failed to send announce message (-14)
ERROR:SCRIPT: /main/main.script:31: attempt to index a nil value
stack traceback:
	/main/main.script:31: in function </main/main.script:13>
ERROR:SCRIPT: /main/main.script:31: attempt to index a nil value
stack traceback:
	/main/main.script:31: in function </main/main.script:13>
WARNING:DLIB: Failed to send unannounce message (-14)
INFO:DLIB: SSDP: Done on address 172.19.50.101
INFO:DLIB: SSDP: Done on address 192.168.0.144

I think it’s best if you could eliminate these errors first before we start looking for any other errors.


#5

A lot of them were due to there not being anyfile for it to load data from interms of saves. which is an issue I was getting around to fixing. I get none of those on startup.


#6

Your main script that controls panning around the map is really not that long, you should be able to go through it line by line and see where things fail. Use print statements, or the debugger. The debugger is a pretty beautiful thing, and quite easy to learn to use. There is also a step-by-step debugging checklist at the end of the debugger manual that is good, use that. That’s the way everyone debugs their code, as far as I can tell.

If you want other people to test your code, well . . . it’s pretty hard for us to do that without all the files needed for it to run properly.


Now that I’ve said that, I may have found your issue. :smiley: Does the panning actually not work when you select something, or is it just any time when the mouse cursor is inside the map area?

There is a problem in your main.script’s on_input function. The very first thing you do is check action.x and action.y to see if they are inside the map area. The arrow key controls for panning the map are inside elseifs after that, so that code only gets run if the mouse cursor is outside the map. You just need to switch things around so you always check the action_id before doing anything else.


How you could have debugged this yourself: (much faster than having to ask for help)

  1. Define the problem.

    More specifically, that would be:

  2. Start from the earliest moment that the problem could possibly start, and check the code step-by-step to see when it fails.
    So, the problem is that pressing the arrow key doesn’t do anything after clicking on the map. So . . .

    1. Check if the main.script is getting input at all. Put a print statement at the first line inside on_input(), run the game, click on the map, and press the arrow key.
      • That works, we are getting input.
    2. Check if the arrow key inputs are working. Put a print statement in the block where we first check for arrow key input. Run the game, click on the map, press the up arrow key.
      • Nope, that fails.
  3. Now that you’ve found specific points where the code succeeds and where it fails, you know the problem must be somewhere in between those two points. Check backwards or forwards to narrow it down until you find the bug. You should only need to check code at the same indentation level.

    If you didn’t notice the problem immediately, you could have put an extra if action_id == hash("up") then... at the start of your on_input() (just after the first debug print statement), so you would be sure that they key input was happening properly, but that something in your code was hijacking the execution flow before it got there. At that point there would be only one line of code at the same indentation level that could possibly be causing the problem.


#7

@ross.grams: That is a really helpful answer Ross! Thank you for taking the time to help support this great community!


#8

Learning to debug is truly a worthwhile skill that makes you a faster, more efficient coder. I should learn it for myself that sometime.


#9

Thank you so much for the feed back guys. Sorry it took me so long to respond, I’ve been really busy. I’ll make sure to look into the debugger and that checklist.