Author Topic: [SOLVED] making a Rupoor  (Read 4536 times)

0 Members and 1 Guest are viewing this topic.

ffomega

  • Full Member
  • ***
  • Posts: 223
    • View Profile
    • Solarus Resource & Tutorial Site
[SOLVED] making a Rupoor
« on: December 03, 2016, 12:30:49 PM »
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.
« Last Edit: December 04, 2016, 10:29:33 AM by ffomega »
My tilesets page can be found here:
http://absolute-hyrule-tutorials.solarus-games.org/

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1192
    • View Profile
Re: [Script Help] making a Rupoor
« Reply #1 on: December 03, 2016, 02:26:16 PM »
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.

ffomega

  • Full Member
  • ***
  • Posts: 223
    • View Profile
    • Solarus Resource & Tutorial Site
Re: [Script Help] making a Rupoor
« Reply #2 on: December 03, 2016, 05:01:40 PM »
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/

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1192
    • View Profile
Re: [Script Help] making a Rupoor
« Reply #3 on: December 03, 2016, 05:06:53 PM »
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

ffomega

  • Full Member
  • ***
  • Posts: 223
    • View Profile
    • Solarus Resource & Tutorial Site
Re: [Script Help] making a Rupoor
« Reply #4 on: December 04, 2016, 09:50:47 AM »
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:

Code: [Select]
if amounts == 3 . . . .
Code: [Select]
if amount = amounts[3] . . . .
Code: [Select]
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/

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: [Script Help] making a Rupoor
« Reply #5 on: December 04, 2016, 10:13:02 AM »
Assuming you're talking about the item:on_obtaining() function still, what you want is:
Code: [Select]
if variant==3 then

ffomega

  • Full Member
  • ***
  • Posts: 223
    • View Profile
    • Solarus Resource & Tutorial Site
Re: [Script Help] making a Rupoor
« Reply #6 on: December 04, 2016, 10:29:10 AM »
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/

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: [SOLVED] making a Rupoor
« Reply #7 on: December 04, 2016, 03:57:23 PM »
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.


ffomega

  • Full Member
  • ***
  • Posts: 223
    • View Profile
    • Solarus Resource & Tutorial Site
Re: [SOLVED] making a Rupoor
« Reply #8 on: December 05, 2016, 02:45:00 AM »
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/