Zelda's Adventure: Solarus Edition

Started by CrookiNari, April 24, 2018, 11:27:48 AM

Previous topic - Next topic
Your problem is that :
1. you are trying to call a reference of movement, but it doesn't exist anymore (when the on_started function finishes, everything defined with local in it is destroyed -or restored to it's previous value if it was already declared outside)
2. you are redeclaring the start() function, which works, because lua allows it, but in your case, would just anihilate it's normal behavior, and as such,  never trigger the movement to actually start.

To fix it, you must place your movement:start inside the on_started function, and remove the function keyword (as well as the associated end keyword)

Ok, I've done that and now there's a new problem.
local map = ...
local game = map:get_game()

function map:on_started(movement:start(traveller_2))
local movement = sol.movement.create("path")
  movement:set_path{4,4,4,4,4,0,0,0,0,0}
  movement:set_speed(20)
end

function traveller_2:on_interaction()
game:start_dialog ("plains_traveller")

end

function map:on_opening_transition_finished()

end

The error this time is:
Error: Failed to load script 'maps/Plain of Andor/ag20': [string "maps/Plain of Andor/ag20.lua"]:14: ')' expected near ':'
It feels like every time I try to fix a problem, a new one pops up in its place. :\

Aww, i think there are some basic Lua notions you need to understand :

1. when you define functions using
Code ( lua) Select
function <id>, the content of the parenthesis is the declaration of variable(s) that you want to be passed on call
so doing
Code ( lua) Select
function map:on_started(movement:start(traveller_2))
is not correct and is likely to generate odd behaviour if not triggering an error.

2. in line :
Code ( lua) Select
  movement:set_path{4,4,4,4,4,0,0,0,0,0}
you forgot the parenthesis around the list content, since you wnt to call the set_path function. (which may be why you got the error message in the first place)

3. finally, your movement will never be started since your function call is misplaced (see 1.).

That's all for now, try fixing your script from all points above, and let me know if it is OK.

Actually, I rather feel inclined to just leave it for now, if now remove it completely in the future. I'm still totally new to programming as a whole and Lua more specifically, so if I keep failing I'll just end up frustrated and likely to abandon the project entirely. Every time I try to program something, even if I apparently follow instructions to the letter it just refuses to work for some reason or another.

I'll just carry on with designing the rest of the game. That at least I'm able to do.

You've done more of a typo than a failure.

Code (Lua) Select

function map:on_started()
local movement = sol.movement.create("path")
  movement:set_path{4,4,4,4,4,0,0,0,0,0}
  movement:set_speed(20)
  movement:start(traveller_2)
end


If you understand Phoenixll54's commenents, the parentheses are just for something else, that's all. Once you've done some more practice, you'll understand the notation and won't make many more of these mistakes. You'll move onto bigger and harder to fix mistakes, like me, haha.


If you really don't want to do much coding though, maybe take that into consideration when you're designing what kind of game you want to make. If you're going to limit yourself to basic gameplay like walking and using the sword (I don't know if you'll have items if you aren't going to program), think about how you can make that interesting.

One approach is games like Firewatch, where because of a really interesting, intimate, and human story, the game is fun to play even though all you do is walk around, really. The beautiful art helps too. There are lots of ways to create and interesting game where you wouldn't have to program as much as a typical Zelda game, but you won't have anything like a typical Zelda game at the end. If you don't want to spend a long, possibly frustrating time teaching yourself to code, then you'll have to accept the limits of what you can do, and try to use those to your advantage to still create an interesting game.

Your addition brings forth this new error repeated:
Error: Illegal direction 2 for sprite 'npc/traveller_2' in animation 'walking'
For context, I want a guy to walk back and forth along a river bank and speak when spoken to. Did I put in the wrong direction numbers?
And I'm not going to forgo programming all together, I was just a little frustrated. I know that the game I want to make won't be easy, but I do want it to be made nonetheless. If it doesn't feel like a Zelda game, then it totally defeats the purpose for its existence. At the very least, I am able to take care of most of the rest of the game design.

June 14, 2018, 11:22:25 AM #51 Last Edit: June 14, 2018, 11:32:51 AM by PhoenixII54
Self-quote from before, since it is an already known issue :

Quote from: PhoenixII54 on May 25, 2018, 11:20:45 AM
The problem is that the engine expects NPC to have 4 sprite directions, and i suppose you only put 2 in your animation. To fix this, you must duplicate some of its directions to have all 4 required, in case you want to add more to the path.

Another thing to precise is that your movement might not loop as you scripted it.Use movement:set_loop() to define whever you want it to loop or not.

Also, you can use timers to enhance your moves, like, walk to point A, wait, turn left, wait, go to point B, wait, etc. I suppose it is not in your priorities yet, but it will definetely add live to your NPC.

Precision : Sprite directions counting always starts from 0, by convention. and reference to : right (0), up (1), left(2) and down (3).

Yes, programming can be difficult, especially for beginners, but by training and not fearing to make mistakes, you will make constant progress as long as you take the time to understand why a particular mistake has been done.

Anyway, hope it helps you fixing this error ;)

I was using the documentation which gave me different instructions, so yours make more sense. Nevertheless, there's still a problem:
Error: Illegal direction 1 for sprite 'npc/traveller_2' in animation 'walking'
Direction 1 is up, correct? I don't know why that would matter since I didn't tell it to move up, and the sprite is capable of displaying all four directions. But the weird thing is, rather than disappearing completely like I normally see happen, he vanishes for about a second and then reappears a few pixels away facing the right and can be spoken to.

June 14, 2018, 01:11:31 PM #53 Last Edit: June 14, 2018, 01:19:01 PM by PhoenixII54
Now this is strange, did you add all four directions in your "walking" anmation set?
If yes, then did you set sprite data to each direction? i suppose that you did, but i wanted to have confirmation

PS : Now that i think, did you create the "walking" set at all ?Again, I suppose that you did, but I wanted to have confirmation

Holy hell how did I not even make a walking animation I feel so dumb
He still doesn't move like he should, kinda sliding upwards a bit before stopping, but there's no error messages this time.

Well, at least you got some progress, and that is the most important thing.  :D

your next step is to make your animation loop, and it is fairly simple : right before starting it, just call movement:set_loop(<boolean value>).
Result will be a continuous movement, which will either do a full back-and-forth movement like you intend, or your npc will just go out of the screen forever -or at least until you leave the map or quit the game.

I've seen the term boolean quite a bit but don't understand what it means.

June 14, 2018, 02:05:25 PM #57 Last Edit: June 14, 2018, 02:10:41 PM by PhoenixII54
To be simple, "Boolean"  refers to a binary variable which can mean true (value=1) or false (value=0)

For more information, don't hesitate to use your preferred search engine. it won't bite, and will expand your culture 8)

PS :
to understand the importance of boolean concept, remember that the whole modern conputing concept is based of the Boole algebra

Oh, ok. It doesn't appear to be making any difference to the code now, though.
local map = ...
local game = map:get_game()

function map:on_started()
local movement = sol.movement.create("path")
  movement:set_path{2,2,2,2,2,0,0,0,0,0}
  movement:set_speed(20)
  movement:set_loop(true)
  movement:start(traveller2)

end

function traveller2:on_interaction()
game:start_dialog ("plains_traveller")

end

function map:on_opening_transition_finished()

end

June 14, 2018, 02:29:12 PM #59 Last Edit: June 14, 2018, 02:30:56 PM by Max
Quote from: CrookiNari on June 14, 2018, 01:26:03 PM
Holy hell how did I not even make a walking animation I feel so dumb
He still doesn't move like he should, kinda sliding upwards a bit before stopping, but there's no error messages this time.

I don't see any issues with your most recent code, so I'm guessing that sliding up a bit is caused by your walking and stopped animation sets having different origins. Origin is a value you set for every direction of a sprite, and for something simple like an NPC, I think the best practice is to set the origin's x value to half the sprite's width (right in the middle) and the y value to 3 px above the bottom of the sprite (generally, height - 3). I'm guessing that might be the problem because I've done that kind of mistake plenty of times.

In general, NPC sprites need a "stopped" and a "walking" animation, you can get away with just stopped if you know they'll never move. I'm pretty sure the engine wants those exact names if it's applying a movement to an NPC entity.

It's also important to make sure in a case like this where the NPC entity is a person, to have the option in the NPC's settings set to "someone", so the engine knows to apply special rules for how people move- for example, automatically calling the "walking" animation when they move, and making them face toward you when the hero speaks to them.


Finally, when you post code on the forums, it's helpful for us helping you if you do the first tag as "["code=Lua"]", with no quotation marks. For one thing, this adds line numbers, which are important for error messages.