Author Topic: hero:walk(path, [loop, [ignore_obstacles]])  (Read 89 times)

Hawkinzon

  • Newbie
  • *
  • Posts: 14
    • View Profile
hero:walk(path, [loop, [ignore_obstacles]])
« 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

Diarandor

  • Hero Member
  • *****
  • Posts: 805
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: hero:walk(path, [loop, [ignore_obstacles]])
« Reply #1 on: November 25, 2017, 12:31:39 am »
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
  1. hero:walk("000222444666", true)

Hawkinzon

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: hero:walk(path, [loop, [ignore_obstacles]])
« Reply #2 on: November 27, 2017, 08:46:49 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
  1. 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

Diarandor

  • Hero Member
  • *****
  • Posts: 805
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: hero:walk(path, [loop, [ignore_obstacles]])
« Reply #3 on: November 27, 2017, 09:12:45 pm »
That's actually pure Lua. The Solarus Lua API assumes that you already know Lua syntax. There are good Lua tutorials online.

Satoh

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: hero:walk(path, [loop, [ignore_obstacles]])
« Reply #4 on: November 28, 2017, 12:20:58 am »
just an addendum to ensure the [var] thing is understood.
Code: Lua
  1. --These are just so the variables are defined
  2. local path = "000222444666"
  3. local loop = false
  4. local ignore_obstacles = true
  5.  
  6. hero:walk(path)
  7. hero:walk(path, loop)
  8. hero:walk(path, loop, ignore_obstacles)
  9.  
These are all valid. But the next option will cause problematic behavior
Code: Lua
  1. --These are just so the variables are defined
  2. local path = "000222444666"
  3. local loop = false
  4. local ignore_obstacles = true
  5.  
  6. hero:walk(path, ignore_obstacles)
  7.  
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.