[SOLVED] making a Rupoor

Started by ffomega, December 03, 2016, 12:30:49 PM

Previous topic - Next topic
December 03, 2016, 12:30:49 PM Last Edit: December 04, 2016, 10:29:33 AM by ffomega
Is there a way to edit the rupeee script to allow negative values for creating a "Rupoor" like the ones in Skyward Sword?  For those who have never played Skyward Sword, a Rupoor (the only game that I know of that had them) was a black rupee that, when collected, reduced your current rupee count by 10.  They were super rare, and were found in treasure chests, or even in grass among the other collectibles.

When I tried adding a variant for rupees as '-10', I got an error message saying that only 0 or positive integers could be used, and I don't want a rupoor that has no value, or will that have to be created as a custom entity? I wanted to make this a random collectable placed within the "random" entity.
My tilesets page can be found here:
http://absolute-hyrule-tutorials.solarus-games.org/

Variants are useful to make several kinds of the same item, for example green rupee, blue rupee and red rupees. The variant number is not the amount of rupees, but just the index of the variant. This is why it is always positive of 0. For example: variant 1 is the green rupee, variant 2 is the blue rupee, variant 3 is the red rupee. You can very well add a variant 4 for the rupoor, that removes some money instead of adding some. Or you can implement it as a separate item, as you prefer.

I'm not having a problem with the variants :)

Code ( lua) Select

local item = ...

function item:on_created()

  self:set_shadow("small")
  self:set_can_disappear(true)
  self:set_brandish_when_picked(false)
  self:set_sound_when_picked("picked_rupee")
end

function item:on_obtaining(variant, savegame_variable)

  local amounts = {1, 5, 10, 20, 50, 100, 150, 250, 300, 400, 500, 1}
  local amount = amounts[variant]
  if amount == nil then
    error("Invalid variant '" .. variant .. "' for item 'rupee'")
  end
  self:get_game():add_money(amount)
end


The problem I had was in line 13; local amounts.  Here you specify the different amounts of each variant, not the variants themselves.  It is here that the console is telling me that I can only have a positive integer or 0.

Also, slightly off-topic:  I want to add the rupee bag to the game and I looked through your code for Solarus DX, but since the game was created before Solarus 1.5, there is no initial game script that tells me where the max money must be set.  I can set a max money count manually but am unable to set one based on the rupee bag variant because i don't know where in your old code to look.
My tilesets page can be found here:
http://absolute-hyrule-tutorials.solarus-games.org/

Ok I misunderstood the problem, sorry. The solution is still easy: call game:remove_money() instead of game:add_money().

In Zelda Mystery of Solarus DX, the initial savegame values were scripted in the savegame menu when creating a new savegame file: https://github.com/solarus-games/zsdx/blob/dev/data/menus/savegames.lua

Thanks Chris :) Now one more thing I need to ask:

How do I have the rupee script check for a specific variant of the rupee (for example: if I have 4 variants of the rupee -- i.e. 1, 5, 20, 100, and I want to create a condition to check the third variant, I tried putting in:

if amounts == 3 . . . .

if amount = amounts[3] . . . .

if amount = 20 . . . .

...out of many possibilities simila to these three, and none of them worked
My tilesets page can be found here:
http://absolute-hyrule-tutorials.solarus-games.org/

Assuming you're talking about the item:on_obtaining() function still, what you want is:
if variant==3 then

I'm a noob xD I didn't associate the condition I needed to check with the function on_obtained, and therefore had the code out of order.  I had the condition on the outside of the function so of course it didn't work xD Thank you for showing me this.  I will try and remember it from now on <3
My tilesets page can be found here:
http://absolute-hyrule-tutorials.solarus-games.org/

Remember, the amount is variant-dependant, an item work with variant, amount is given by the variant defined by the Lua code, this is simple to remember.


I am new to learning lua so the concept too is new to me :) Thanks a lot ^_^
My tilesets page can be found here:
http://absolute-hyrule-tutorials.solarus-games.org/