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.

What is eval, and how i can use?

Well, that's my question, I've seen in a lot of scripts, but I never figured what do, and for what?..

And how I can use this?
__-

And the other question, I see in several scripts a method or whatever that puts 'include', just below the script header:


Code:
Class Game_Maker

 

include something

Those are my question of the day.
 
Okay, first the include.
This will add to the current scope (class/module/program) the existing procedures on the specified module. So let's say...
[rgss]class Person
  include Communication
[/rgss]
This will add to Person all the functions from Communication. So if there's a def talk at Communication, Person will be able to use it as well.

eval is a bit difficult to explain. When you're coding, at the Script editor, you might need to execute dynamic codes. You can create a String that holds a code piece and execute it using eval.
[rgss]# This will change the Switch 1 to false
codeA = "$game_switches[1] = false"
eval(codeA)
 
# This will return true whenever the condition is met
case @index
when 0
  @condition = "true"
when 1
  @condition = "$game_party.actors.size > 0"
when 2
  @condition = "$game_party.gold > 0"
end
codeB = "return true if " + @condition
result = eval(codeB)
[/rgss]

Eval is specially used for "Execute script" on events. At the Event editor, you'll type a RGSS code that's kept on a String. When the Event is run, this String is executed using eval.


SEE YA!!!!!
 

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