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.

[Resolved] Printing a message if switch is OFF.

Jason

Awesome Bro

Hi,

So before the game starts, I've got the idea to make it say a few things in text boxes, I know the code is;

Code:
 

p "Blaa blaa."

 

However, I'm trying to make it only print while a switch is turned off, as I don't want it appearing everytime the player starts the game up, cause it'll get annoying, I only want it showing the first time.

I was hoping something simple like;

Code:
 

if $game_switches[1] == false

  p "Blaa blaa."

  else

end

 

I even tried adding an initialize (Don't ask why, I had no idea if it'd help or not, I'm still a rookie scripter, lol);

 

def initialize

  if $game_switches[1] == false

    p "Blaa blaa."

  else

  end

end

 

Would do the trick, however I seem to get an error;

Code:
 

Script "TestPopupText" line 1: NoMethodError occured.

 

undefined method `[]' for nil:NilClass

 

Now, I don't see how the [1] is an undefined method as it's obviously the switch.

Does anyone have any ideas as to what the problem could be ? Am I doing something COMPLETELY wrong here ?

Thanks.
 
$game_switches is a game data that isn't created until new game pressed. You would be better off creating a text document or something that records outside rmxp completely for this. Then just checking if it exist or not.

if # file doesn't exist
p "blah"
# make file
end
 

Jason

Awesome Bro

And how would I check to see if that file exists ?

Say, if I made a .txt document called "Null", how would I check that it doesn't exist in the directory ? and how would I make it afterwords ? Wouldn't it be easier to make the file first, and check that it IS there, and then delete it ?

Either way, I don't know how to do it, hah.
 

Jason

Awesome Bro

Thanks Near, that actually works exactly like I wanted it,

Is there a way to make it so IF it exists, like

if FileTest.exist?("Null.txt")

Cause if so, I've got even more ideas up my sleeve !
 
You mean like, you create the file before releasing the game, and delete it after it prints the message?

Also, if you want my advice, you should have a text file, containing a message and then, display the message in the text file, and then delete it. You can do that with a separate directory in your data folder, or even in your main folder, and you can do that with multiple messages. And, if you didn't already know, when you have the file in a sub-folder instead of the game's main folder, you need to do this: FileTest.exist?("<folder>/<file>"), instead of exist?("<file>")

And the function to delete files is 'File.delete("<file>")'
 

Jason

Awesome Bro

Hmm, and how would I display the message thats inside the .txt file ?

Also, cause I just tried and it doesn't do it, how would I make it, so when it creates the .txt file, it goes into another directory ? Cause I made a folder called Other, and did this;
Code:
 

unless FileTest.exist?("Other/Null.txt")

 
And it doesn't show the message if the .txt is in the Other folder, however, when it creates the .txt, it ends up inside the main directory,

Any ideas ?
 
If you want to display the message inside the .txt file, you have
to put in:

[rgss] 
file = File.open("Other/Null.txt")
p file.read
file.close
 
[/rgss]

and to create a file in a new sub-folder:

[rgss] 
file = File.open("Other/Null.txt")
file.write("something")
file.close
 
[/rgss]

Mess around with that for a while.
 

Jason

Awesome Bro

Hmm yeah thats doing what I want,

Could I possily do something like;
Code:
 

if FileText.exist?("Other/Null.txt")

  file = File.open("Other/Null.txt")

  p file.read

  file.close

else

  

end

 
So it will only open the file and read the text IF it exists ?
 
Yeah, that works just fine.

And also, if you don't mind, I'd like to use this idea in my game (which is going well, if you want to know). I like the idea of the in game messages, with seperate data files.

And another good idea from me:

What I would do for creating the messages, is have it so that on the first run of the game, it automatically creates a new directory, and puts in your messages, and also, if you want to have fun with it, you can try saving the messages in another format (like *.rxdata, or *.shizzle) because you can make your own formats that are only readable by your game. And if you need help exporting your messages, just ask.
 

Jason

Awesome Bro

Well actually there are three main functions for this system, one is for the welcome message, while the other two will remain unknown to everybody except me, until the game is played :wink:

I'll give you a hint, I'm a fan of the Metal Gear Solid games...

Edit--

Hmm I seem to get an error with this line'
Code:
 

if Filetest.exist?("Other/Null.txt")

 

Uninitialized constant Filetest

Any ideas ?
 

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