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.

Is it possible to call script from text file?

Hi,

I have 2 questions here:


1) Is it possible to call script from text file?

for example, I create script.txt in my game folder, and text in script.txt is
Code:
class My_New_Class
attr_accessor :newvar

def initialize
@newvar = 0
end
end

Is it possible to make those text in text file to script?


2) How can I make new class which class name is from string in variable?

for example,
Code:
$game_variables[1] = "Game_New_Class"

Can I create new class called "Game_New_Class" with script?



Thanks in advance :)
 
Thanks! Arbiter

For number 2,
I means if I want to make new class that has class's name from variable.

Code:
$name = "New_Class_Name"
class $name

definitely not work,

Thanks again. :)
 

khmp

Sponsor

Are you trying to create an instance of this class? But have the name of the class stored inside this global "$name"?
Code:
$name = New_Class_Name
thing = $name.new
If you are stuck with the string use eval.
Code:
class New_Class_Name
  # stuff
end

$name = eval("New_Class_Name")
a = $name.new
p a.type # This will print New_Class_Name.

Good luck with it woratana! :thumb:
 

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