Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Christopho

Pages: [1] 2 3 ... 68
1
Development / Re: Screen vs entity position?
« on: May 15, 2017, 05:08:27 pm »
entity:get_position() give coordinates relative to the map. You can find coordinates relative to the screen if you just subtract the camera position.

2
Development / Re: pcall metatable?
« on: May 05, 2017, 02:05:09 pm »
Ok, so your question is actually independent from metatables or Solarus, it is about the passing a value of type function vs calling a function.
Code: Lua
  1. function metatable:example()
  2.   --some code
  3. end

This defines a field "example" (of type function) on the object "metatable", and not an "example" global value.

Which means that you can call it like this, assuming you  have an entity called my_entity:
Code: Lua
  1. my_entity:example()
and not like this
Code: Lua
  1. example() -- Does not work: example is nil

If you want to make a value of type function instead of doing the call entity:example(), just wrap the call it in a function:
Code: Lua
  1. local function f()
  2.   my_entity:example()
  3. end
Then it is a value of type function (and not a function call anymore, this is the trick!) so you can pass it to anything that wants a value of type function, like pcall, sol.timer.start, etc.
Code: Lua
  1. local success = pcall(f)
  2. if success then
  3.   ...
  4. else
  5.   ...
  6. end
  7.  

You can even keep it anonymous if you prefer:
Code: Lua
  1. local success = pcall(function()
  2.   entity:example()
  3. end)
  4. if success then
  5.   ...
  6. else
  7.   ...
  8. end
  9.  

3
Development / Re: pcall metatable?
« on: May 05, 2017, 11:21:31 am »
Your code is a correct way to catch errors.
But you were talking about metatables in your first message, what do you want to know exactly?

I don't know if it answers your question, but sol.main.get_metatable() returns nil if the parameter is an unknown type name. It will only throw an error if the parameter is missing or is not a string.

4
Development / Re: pcall metatable?
« on: May 05, 2017, 10:01:00 am »
What do you mean?

5
Development / Re: 2 Player
« on: May 02, 2017, 10:32:01 am »
For networking multiplayer, you don't need to change the C++ code of the engine. You can use a Lua networking library like LuaSocket. It is true that there is no direct networking support in the Solarus API yet: you will have to do a lot of things manually, but no C++.

6
Development / Re: Create a new "attack_consequence"
« on: April 28, 2017, 12:37:05 pm »
You can add your own attacks with scripts. Don't use enemy:set_attack_consequence(), but instead, define your own functions. This is what I do with several items like the hammer, the hookshot, etc.
See for example the hammer script here: https://github.com/solarus-games/zelda-roth-se/blob/dev/data/items/hammer.lua#L114
I create functions enemy:get_hammer_reaction(), enemy:set_hammer_reaction() and enemy:set_hammer_reaction_sprite(). Metatables are used so that all enemies have the new functions.

7
Development / Re: Freeze hero?
« on: April 27, 2017, 09:09:25 am »
I don't understand the question. You can call hero:set_animation() when the hero is frozen, there is no problem.

8
Your projects / Re: Zelda: Book of Mudora
« on: April 12, 2017, 09:02:12 am »
3) Just use a monospaced font and detect characters that use two bytes.

9
Your projects / Re: Zelda: Book of Mudora
« on: April 11, 2017, 10:59:09 pm »
Can you tell me again what was wrong and why detecting two-byte characters did not work?

10
I meant diagonal water/shallow water obviously, sorry.

11
Other water tile patterns have the wrong ground:

The ones in red should be deep_water instead of shallow water.
And the ones in yellow should be diagonal water/walls instead of shallow water.

Otherwise, the hero can go way too much into water before swimming or drowning:

12
Development / Re: Movements with camera?
« on: April 07, 2017, 06:17:55 am »
Use map:get_camera()

13
Development / Re: item icons
« on: April 06, 2017, 09:10:07 am »
Check the dialog box script to know where it finds icons. In my game, it is in the file sprites/hud/dialog_icons.png. The number is the index of a 16x16 square in that file.

14
Development / Re: Small Key HUD ?
« on: April 05, 2017, 09:34:59 pm »
Content que tu aies compris et pas juste reproduit du coup ^^
Tu vas pouvoir continuer à progresser :)

15
Development / Re: Small Key HUD ?
« on: April 05, 2017, 06:01:25 pm »
Une astuce est de faire comme mon code plus beau :
Code: Lua
  1. local count = game:get_value("small_keys_save") or 0
  2.  
Rajouter "or 0" au bout pour initialiser à 0 si c'est nil.

Autre solution, initialiser au début du jeu (dans initial_game.lua) mais je me vois mal initialiser toutes les futures variables du jeu dès le départ.

Pages: [1] 2 3 ... 68