War battles tutorial issue - movement script


#1

I’ve been following the war battles tutorial, and copied the script, yet the player sprite isn’t moving with the inputs. !

IMG_20180108_231322|281x500


#2

Be sure to configure ‘game.input_binding’ for the keys.

“key-up” input should match “up” action, and so forth.


#3

Yeah it’s configured, I’ll post a photo tomorrow. Like I said, I followed the steps…


#4

You can go through the script step-by-step and use print() to make sure each part is doing what you expect. First I would put print(action_id) in your on_input function (before any ifs). If a bunch of inputs start showing up in the console when you press buttons, then you know your script is running and getting input. Then move the print to the actions to make sure they’re firing correctly. If that’s all good, print something in update, where you . . . Aha! Nevermind, I see the issue.

You’re missing a vital line in your update function. There should be a third line in the if self.moving then block, it should be go.set_position(pos). See the player movement script in the tutorial.


#5

Ah, yes - Looking closely, I can actually see the game.input_binding file open in your screen shot. :no_mouth:

I think @ross.grams has noticed the real culprit.


#6

Hey thanks! It’s my first time writing code (even if it’s copying). Amazing how I missed that one line XD Enjoying the tutorials though, and I’m learning quite a bit.


#7

That’s cool! Gratz on starting your developer journey with Defold then.
May I ask what inspired you to start learning to code with Defold? (rather than something else)


#8

Great! If you have feedback and ideas for improvements and/or new tutorials, please don’t hesitate to post.


#9

Well, I have an idea that id like to implement into a game. My inspiration are games like Baldur’s Gate and Icewind Dale, I love the type of gameplay, and I know lots of people of my age want to play new games, but with the style of those games we played back then you know?


#10

I’ve not looked, but an Rpg tutorial would be nice, not the JRPG type though, western style. I like the software, it’s pretty easy to use and your tutorials are very descriptive, well done!


#11

I’m having another issue XD after adding collision script to the rockets and tanks, the rockets now dont move, nor do they explode. Here’s the script and the error message…


#12

Can’t you copy-paste code and console errors instead of taking pictures of your screen? It’s a lot harder to read this way.

The error message mentions that you’re trying to multiply one value with nil. This indicates that one variable isn’t assigned a value. Perhaps self.dir or self.speed. Print all the values used on line #12 to figure out which one is nil.


#13

I only have Internet access with my mobile phone XD once a day I go to the cafe to connect, next time I’ll do that.


#14

Ah, ok, no worries then! Anyway, check and print the values used on line 12. One of them is nil.


#15

By print you mean…? Sorry, I’m very new at this.


#16

You can use

print(...)

To print values to the debug log. I’d recommend describing what your printing by going

print("My Value is: " .. my_value)

Here’s a description of everything. "My Value is: " is just a string. You can type any string in the print function and it will print it. The ‘…’ (Should be two dots, but post auto-corrects it to 3) is called a concatenation. It adds a string to a string.

If you get an error saying something like: “attempt to concatenate (my_value). (my_value) is not string.” All you have to do is change the print function to this:

print("My Value is: " .. tostring(my_value))

#17

Note that you can comma separate values in a print statement so you don’t have to convert before concatenating:

print(“My value is:”, my_value)

PS Another way to check which value is nil is to use the integrated debugger and set a breakpoint.


#18

Okay and when I find the error I change the variable of the problem part of the script? In other words, the problem here is the number correct?


#19

Well, it’s hard to say. Is it a typo? Is it the fact that you’ve forgotten to give the variable a value somewhere else in your script? Double check the script compared to the tutorial.


#20

The error:script is telling me script:12 in function. I assume the error is with…dir. It’s weird because as far as I can see the script is the same as in the tutorial, the exception being line 1 which the tutorial doesn’t really specify if I have to delete it or not. I tried deleting it, but just get the same issue. However when I deleted it tells me attempt to perform. I arithmetic on field ‘dir’ (a Nil value) and the traceback changes to /main.rocket.script: 10 in function </main/rocket.script:8> like i said, the script matches the tutorial for this step, later on today I’ll double check for typos.