hero:walk(path, [loop, [ignore_obstacles]])

Started by Hawkinzon, November 24, 2017, 11:28:05 PM

Previous topic - Next topic
Hi all!

Since I'm totally new to lua scripting I would like someone to explain how this works
hero:walk(path, [loop, [ignore_obstacles]])

I've been reading the documentation for the last two evenings and tried different solutions to get this to work but I can't figure it out.. I understand the function and what it can do, but I can't get it to work.
The function I was is to have my hero to freeze (for the player) and then walk a path of 2-3 steps south/down after I step on a sensor when I haven't a specific item obtained

Can someone please write an example on how this works?

BR
Hawkinzon

Quote from: Hawkinzon on November 24, 2017, 11:28:05 PM
Hi all!

Since I'm totally new to lua scripting I would like someone to explain how this works
hero:walk(path, [loop, [ignore_obstacles]])

I've been reading the documentation for the last two evenings and tried different solutions to get this to work but I can't figure it out.. I understand the function and what it can do, but I can't get it to work.
The function I was is to have my hero to freeze (for the player) and then walk a path of 2-3 steps south/down after I step on a sensor when I haven't a specific item obtained

Can someone please write an example on how this works?

BR
Hawkinzon

It is all explained with detail in the Lua API:
http://www.solarus-games.org/doc/1.5/lua_api_hero.html#lua_api_hero_walk

You only need to know what strings and booleans are. The notation "[var]" means that the variable "var" is optional.

An example that should make the hero turn in circles (if there is no obstacle in the path) in a loop:
Code (Lua) Select
hero:walk("000222444666", true)
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Quote from: Diarandor on November 25, 2017, 12:31:39 AM
Quote from: Hawkinzon on November 24, 2017, 11:28:05 PM
Hi all!

Since I'm totally new to lua scripting I would like someone to explain how this works
hero:walk(path, [loop, [ignore_obstacles]])

I've been reading the documentation for the last two evenings and tried different solutions to get this to work but I can't figure it out.. I understand the function and what it can do, but I can't get it to work.
The function I was is to have my hero to freeze (for the player) and then walk a path of 2-3 steps south/down after I step on a sensor when I haven't a specific item obtained

Can someone please write an example on how this works?

BR
Hawkinzon

It is all explained with detail in the Lua API:
http://www.solarus-games.org/doc/1.5/lua_api_hero.html#lua_api_hero_walk

You only need to know what strings and booleans are. The notation "[var]" means that the variable "var" is optional.

An example that should make the hero turn in circles (if there is no obstacle in the path) in a loop:
Code (Lua) Select
hero:walk("000222444666", true)

Yes I have been looking into the Lua API but unfortunately it doesn't give me an example of how the strings and booleans can be written.

But thanks alot for the tip! :)

BR

That's actually pure Lua. The Solarus Lua API assumes that you already know Lua syntax. There are good Lua tutorials online.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

just an addendum to ensure the [var] thing is understood.
Code ( lua) Select

--These are just so the variables are defined
local path = "000222444666"
local loop = false
local ignore_obstacles = true

hero:walk(path)
hero:walk(path, loop)
hero:walk(path, loop, ignore_obstacles)

These are all valid. But the next option will cause problematic behavior
Code ( lua) Select

--These are just so the variables are defined
local path = "000222444666"
local loop = false
local ignore_obstacles = true

hero:walk(path, ignore_obstacles)

The second argument is being supplied with "ignore_obstacles", but the second argument is always "loop" so you're just feeding the loop argument the value of ignore_obstacles. The game will still treat it as the loop argument regardless of its variable name.

If you want a path that will not loop, but will ignore obstacles, you have to supply both arguments. You cannot omit an argument from the middle of the list if you plan on using one farther down that list.

I hope that hasn't muddied the issue any.

I personally like the official Lua 5.1 reference manual. Its clean, and concise, and generally pretty self explanatory.
https://www.lua.org/manual/5.1/
Some things are covered in separate chapters though, so be sure to at least glance at some of the earlier pages even if the one you need is later on.
Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.