War Battles tutorial support thread - post your questions here

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

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

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

2 Likes

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

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.

4 Likes

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.

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.

8 Likes

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)

2 Likes

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

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?

1 Like

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!

1 Like

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…

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.

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.

3 Likes

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

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

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))

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.

2 Likes

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?

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.

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.

1 Like