Joined
Jun 5, 2020
Messages
8
Reaction score
0
First Language
Italian
Primarily Uses
RMXP
Hi guys! I need some help to fix this trouble.

I'm scripting a Scene that simulates a wrestling pinfall.
During the action the player needs to push a button repeatedly, that adds one point of HP any time, to reach 30% of MAXHP to escape.

I have two problems:

- In time update I put percentage formula but it doesn't work. There's no difference if i write extended or not ($game_actors[1].hp / 100 * 30 )
- I need to stop time if the condition of 30% is reached

There is my script :

Code:
  def time
     @time += 1
     case @time
     when 100
        @conteggio.bitmap = RPG::Cache.picture("3") rescue nil
     end
     case @time
     when 50
        @conteggio.bitmap = RPG::Cache.picture("2") rescue nil
     end
      case @time
      when 0
        @conteggio.bitmap = RPG::Cache.picture("1") rescue nil
        end
     if @time > 150
       if  $game_actors[1].hp >= 30%
         $game_variables[5] += 1
         $game_switches[1] = true
         $game_map.need_refresh = true
         $scene = Scene_Map.new
       else  $game_actors[1].hp <= 30%
       $scene = Scene_Gameover.new
       end
       end
     end


The result is... The game continue in the same way... With 0 or 100% HP
 
Last edited:

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,828
Reaction score
4,763
First Language
English
Primarily Uses
RMMZ

I've moved this thread to Learning Ruby and RGSSx. Please be sure to post your threads in the correct forum next time. Thank you.

 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
351
Reaction score
136
First Language
English
Primarily Uses
RMXP
When dividing with integers, particularly for finding percentages of something, it's imperative that you multiply first then divide. Integer division does not convert to decimals.

50 / 100 * 30 = (50 / 100) * 30 = 0 * 30 = 0
50 * 30 / 100 = (50 * 30) / 100 = 1500 / 100 = 15

Whereas something like this is okay (note the 100.0, turning this into a floating point division).
50 / 100.0 * 30 = 0.5 * 30 = 15.0

But integer division is faster than floating point division, so it's best you stick with the first solution.

Code:
def time
  case @time
  when 0
    @conteggio.bitmap = RPG::Cache.picture("1")
  when 50
    @conteggio.bitmap = RPG::Cache.picture("2")
  when 100
    @conteggio.bitmap = RPG::Cache.picture("3")
  end
  @time += 1

  if @time < 150
    if $game_actors[1].hp >= $game_actors[1].maxp * 30 / 100
      $game_variables[5] += 1
      $game_switches[1] = true
      $game_map.need_refresh = true
      $scene = Scene_Map.new
    end
  else  
    $scene = Scene_Gameover.new
  end
end
 

Latest Threads

Latest Profile Posts

Kind of relieved that I had medibang installed when I need to edit Sprite I was about to download gimp but I remember I had medibang installed lol
Voting for the first round of the Map Madness Tournament is now live! Vote for your favorite in each matchup!

Finally started working on Grim Trigger episode 2 today :LZScat: it's half comic/half visual novel!

GfY3Rwj.png
Is it interesting to get more backstory on villains? A key moment in their past, their childhood, or maybe something that shows they've always been that way? To see or not to see?
"Everything tastes like chicken until it's chicken, then it doesn't taste like chicken."
Context: chicken samosas do not taste like chicken. I thought it was veggie samosas.
Just another ordinary evening.

Forum statistics

Threads
110,365
Messages
1,052,625
Members
143,398
Latest member
Rintosi
Top