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,821
Reaction score
4,754
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
345
Reaction score
128
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

Kes
After a few hectic months, my hiatus is over, and I'm now back. Good to see so many familiar names posting. And a forum update while I was away.
V1.3 of Demo, a new concept artist on the team, character voices are coming into light more... I'm happy to say that the fangame is making good progress.
Ami
--- Stolen Item ---

M.Figher: I want to sell this Stone
Fence: Then...i can buy you 1500G
M.Figher: It's Deal!
(3 Days Later)
F.Fighter: M.Figher,Do you know about Stone that Mayor keep it in his Office? It's missing
M.Figher: Ahh,is that so... (Actually,i Stole it and Sell it to the Fence a few Days ago)
I've spent some cash on foley and other sound effects. I wonder sometimes if I made a poor choice, but I remember that I really want to improve the sound of my games. n...n; My frugalness haunts me sometimes.

Forum statistics

Threads
108,854
Messages
1,040,066
Members
141,290
Latest member
theolharicot
Top