Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Game Variable Control

Game Variable ControlVersion: 1.0
By: game_guy aka gameguy27

Introduction

Well say you're scripting and it involves typing out $game_variables[id] += whatever
or something like that. This small scriptlet allows you to shorten the above line

THIS WORKS FOR VX AND XP
Features

  • Use shorting line instead of $game_variables

Screenshots

N/A

Demo

N/A

Script



Code:
=begin

Gv.getval(id) # Get the value of the game variable 

Gv.setval(id, val) # Set the value of the game variable

Gv.addval(id, val) # Add value to the game variable

Gv.subval(id, val) # Subtract value from the game variable

Gv.multval(id, val) # Multiply value to the game variable

Gv.divval(id, val) # Divide value by the game variable

 

id = variable id

val = the value you want to set/add/subtract/multiply/divide the variable to

=end

module Gv

  def self.getval(id)

    return $game_variables[id]

  end

  def self.setval(id, val)

    $game_variables[id] = val

  end

  def self.addval(id, val)

    $game_variables[id] += val

  end

  def self.subval(id, val)

    $game_variables[id] -= val

  end

  def self.multval(id, val)

    $game_variables[id] *= val

  end

  def self.divval(id, val)

    $game_variables[id] / val

  end

end

 

Instructions

Ok instead of using something like this
$points = $game_variables[id]
you can use this instead
$points = Gv.getval(id)

To me it makes things alot quicker. Here are the different operatoins you can use

Gv.getval(id) # Get the value of the game variable
Gv.setval(id, val) # Set the value of the game variable
Gv.addval(id, val) # Add value to the game variable
Gv.subval(id, val) # Subtract value from the game variable
Gv.multval(id, val) # Multiply value to the game variable
Gv.divval(id, val) # Divide value by the game variable

id = variable id
val = the value you want to set/add/subtract/multiply/divide the variable to

FAQ

None

Compatibility

Compatible with everything.

Credits and Thanks

game_guy aka gameguy27 ~ making it

Author's Notes

I am not sure if this would be considered a scripters tools seeing you can also do this by script call. But I think of this mostly as a scripters tool.

Terms and Conditions

Use as you wish.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top