Ruby/RGSSx questions that don't deserve their own thread

Yes, bitmaps can only be shown when drawn in Sprite objects. At least AFAIK, without using any dlls or something.
im trying to make a list script for random speech by using an array and found a way to get it to make a random choice but now cant get it to display through a call. it keeps tripping on undefined .add when i add $game_message.add and when i drag over the method it trips on .push

am i missing something the script is

phrase = ["this","is a","test"]

speech = phrase.sample

$game_message.add(speech)
Maybe undefined method add for nil:nilClass is your error?

If it's not, can you post the whole error with the place where it happens and if it's happening in Game_Interpreter 1411 then post your last script call before crash

From where are you calling $game_message.add ?

Are you not on the map or in battle?
Show us the whole script segment where you have that?


I'm guessing you don't actually put the call into a method or class, or at least whatever you are doing is trying to add the text to $game_message before $game_message even exists.
this is what i got to:

#simple speech randomizer
#version 1.0
#worlwake std
#free for all projects with credit

#
@data[x]#create a variable in database and change x to that variable
#
= speechcallwwstd

#=============================================================================================
#++++++++++++++++ set phrases here +++++++++++++++++
#++++++++++++++++ use quotes and comma +++++++++++++
#++++++++++++++++ on all but the last phrase +++++++
#=============================================================================================

phrase[
#------------------- start below ---------------------------}
"Power to the people!",
"Hello.",
"How are you today?",
"this is so exciting!",
"..."
#---------------------- end --------------------------------}
]
#--------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------

#============================================================================================
#++++++++++++++++ beware of below +++++++++++++++++++
#============================================================================================

speechcallwwstd = $game_message.add(speech)
speech = phrase.sample
@data[x] = puts

on event:

$game_message.add(@speech)

@data[x] is set to var 5   named

error game message line 99

undefined method '+' nil:nilclass

error on npc call

edit: i understand that half of the code is not in use at the moment but i will clean it once i get the main bit to work
Edit: *slash*

@Shaz

Sorry, I thought it was simple enough to warrant a post in this thread instead of a whole thread of its own.
That is not a "question that does not deserve its own thread".


Please start a new thread in the Learning Ruby and RGSSx or the RGSSx Script Support forums.
@worldwakestd

I really have no idea where have you put what, but if put all of that in one script slot, then it's surely not gonna work.

If you are interested why, it's because $game_message isn't assigned yet.

Tell us when do you want to randomize speech, and some more information about it, because it's not looking good right now...
im trying to have it where the player talks to an npc and it goes through a list of preset phrases and picks one then displays it as if i typed it into show text but i will have to many to use a common event.
@worldwakestd

That script is full of errors.

@data is not defined anywhere, but you want to get a data from it assuming that it is an array/hash already. I am surprised that it won't throw an error right on that line.

Same for the 'phrase' variable. It is not yet defined, and it won't even try to read a data from an array/hash here, because there can be no key set in a hash named '"text1","text2","textN"'.

If you want to define an array, you use the equation sign. Without that, the code will search for a data in an array or hash instead of setting anything.

phrase["string1","string2","stringN"] # This line should throw an error instantly when it is read.phrase = ["string1","string2","stringN"] # This line is correct. It sets the 'phrase' up to be an array of strings.Here is a short little snippet you can use to show up randomized texts in your game:
Spoiler
Code:
# Call a random text with this script call in an event:##   show_rand_txt(key)## Replace 'key' with a valid key from the 'Texts' setting hash below.## Examples: show_rand_txt(1),  show_rand_txt('shopkeeper2')module RandTxt  # This is wher you set your random texts up.  # You can make multiple arrays with different keys in the hash settings,  # so you can show different random texts for different events.  # Make sure to not use the same key more than once, or else the latter one  # will overwrite the previous one!  Texts = {    1 => [ # 1st random array for texts, using an integer number for key.      "Sample text number 1.", "Second text, yay!",      "Another one, ohh noes!", "Here comes the last one! o.o",      # And so on... Add as many texts as you want.    ],    :guard2a => [ # 2nd random text array, using a symbol for key.      "First text in second settings.", "1 + 1 = 2",      "Third one for the charm!",    ],    'shopkeeper2' => [ # 3rd random text array, using a string for key.      "No way, a text again!", "Okay, tired of texts...",    ],    # And so on... Add as many arrays as you want.  }  endclass Game_Interpreter  def show_rand_txt(key)    txt = RandTxt::Texts[key].sample    $game_message.add(txt)    wait_for_message  end  end
Put it anywhere below Materials, but above Main.

You set up your text arrays in the settings, and call a random text from an array you set up in the script with the provided script call in the game.

You can name your random arrays however you want, so you don't get lost in it in case you got hundreds of texts like that.

It is just a basic text randomizer without the ability to show up faces in your messages, but with a few lines added here and there, that can be done easily as well.
thank you this is what I was looking for. I clearly need more work with array/hash. and yes I noticed even when messed up like that it wouldn't throw the refers ?8(? it might have seen my mess and ran. again thank you
Hey can I get a quick example of how to do a core module for a splash screen using an array to list the images and get the graphic method to run with array.each

As this would be an option for my core I would like to have as little code tampering as possible.
You'd set up the array in the initialize method, call a method to load the first image, and set a flag saying it's fading in.


In the update method you'd determine whether it's fading in or fading out - if fading in, increase the opacity by x, see if it's >= 255, and if it is, change it to be fading out; if it's fading out you would decrease the opacity by x, see if it's <= 0, and if it is, call the method to load the next image.


Once the opacity is 0 or less and there are no more images to display, change the scene.


Base it on the other scenes/windows that have an initialize, update and dispose method.


Make sure you dispose the bitmaps each time you load a new image, and right at the end.
I think Shaz or someone else made a better way for that, you just put the images into a folder and it reads from there... No code tampering at all to add/remove images.
sorry i dont understand this error:

Spoiler
Script " line 37; Syntax....unexpected keyword_else, expecting ':'

else
this is what i put:

Spoiler
module SceneManager
  #--------------------------------------------------------------------------
  # Overwrite method; Get First Scene Class
  #--------------------------------------------------------------------------
  def self.first_scene_class
    if Setup::splash_start??
    $BTEST ? Scene_Battle : Splash_Intro
    else
         $BTEST ? Scene_Battle : Scene_Title
  end
end
end
That's because Setup::splash_start?? should be changes to Setup::splash_start? or Setup::splash_start

You cannot name methods with two ?'s as far as I know.
the method only has one ? in its name. the second is checking if object is true

and i got that part to work bc = true was throwing at [=]

and == true throws undefined method
If you have defined a method in Setup module as splash_start?

then change your if condition to Setup::splash_start?

And if you haven't defined it at all, define it.

Overall it should look like :

Code:
module Setup  def self.splash_start?    # your code here  endendmodule SceneManager  def self.first_scene_class    if Setup::splash_start       # Add what happens here    else       # Also here    end  endend
No, you don't have to add "?" in if statement. "?" is only used in this setup

condition ? true : falseEither you make it into this

if Setup::splash_start? $BTEST ? Scene_Battle : Splash_Introelse $BTEST ? Scene_Battle : Scene_Titleendor this, (this is a bad example though, avoid this)

Code:
Setup::splash_start? ? ($BTEST ? Scene_Battle : Splash_Intro) : ($BTEST ? Scene_Battle : Scene_Title)
this is my change:

Spoiler
  def self.first_scene_class
    if Setup::splash_start??
    $BTEST ? Scene_Battle : Splash_Intro::Splash_logo
    else
         $BTEST ? Scene_Battle : Scene_Title
  end
so this will help heres my work:

Spoiler
module Setup
    Splash_Image = ["Graphics/Pictures/WarStormGames"]
  def splash_start?
    activate_Splash_Screen = true
  end

end
module Splash_Intro

    class Splash_logo
    def start   
      super
      id = 0
      make_splash_logo
    end
      
    def make_splash_logo
      @sprite=Sprite.new  
      @sprite.bitmap=Cache.picture(Setup::Splash_image[id])
      @sprite,opacity=0
    end
    def update   
      super   
      Graphics.wait      = 15   
      Graphics.fadeout   = 1  
      @sprite.opacity    = 255   
      Graphics.fadein    = 30   
      Graphics.wait      = 130   
      Graphics.fadeout   = 30
      if id < Setup::Splash_Image.length
        then id ++ 1
      else if id >= Setup::Splash_Image.length
        then SceneManager.goto(Scene_Title)
      end
    end
  end
end
end

module SceneManager
  #--------------------------------------------------------------------------
  # Overwrite method; Get First Scene Class
  #--------------------------------------------------------------------------
  def self.first_scene_class
    if Setup::splash_start?
    $BTEST ? Scene_Battle : Splash_Intro::Splash_logo
    else
         $BTEST ? Scene_Battle : Scene_Title
  end
end
end

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/