The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Zethzune on December 31, 2008, 09:53:40 PM

Title: Using Messages in RGSS
Post by: Zethzune on December 31, 2008, 09:53:40 PM
I want to make the Change Items event tell you when you have received an item, but I can't figure out how to call the standard message function from inside a script. I'm also trying to make it figure out whether your gaining or loosing the item, and if it's more than one at a time, how many were gained/lost.

My half-assed changes have been commented out


  #--------------------------------------------------------------------------
  # * Change Items (From Interpreter4)
  #--------------------------------------------------------------------------
  def command_126
    ## changed_item = @parameters[1]
    ## if value is not negative
    ## $game_temp.message_text = "You gained \C[1]" + $data_items[changed_item].name + "\C[0]!"
    ## else #losing item
    ## $game_temp.message_text = "You lost \C[1]" + $data_items[changed_item].name + '\C[0]!"

    # Get value to operate
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    # Increase / decrease items
    $game_party.gain_item(@parameters[0], value)
    # Continue
    return true
  end
Title: Re: Using Messages in RGSS
Post by: modern algebra on January 01, 2009, 03:30:16 AM
Well, you have the right idea: all you need to do is change $game_temp.message_text

You have some syntax problems though. Before that though, your stuff should be below "value = operate ...." line, and @parameters[1] doesn't hold the item, @parameters[0] does. For syntax, the condition ought to be:

if value > 0

Instead of havine else, you ought to have elsif value < 0 since you don't want a message to play in the rare case that the value is 0 (which can happen).

and you mess up the quotations on the last \c[0] - one is a single quote and the other a double quote. You are also missing the end.
so your method should look like this:


  #--------------------------------------------------------------------------
  # * Change Items (From Interpreter4)
  #--------------------------------------------------------------------------
  def command_126
    # Get value to operate
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    changed_item = @parameters[0]
    if value > 0
      $game_temp.message_text = "You gained \C[1]" + $data_items[changed_item].name + "\C[0]!"
    elsif value < 0
      $game_temp.message_text = "You lost \C[1]" + $data_items[changed_item].name + "\C[0]!"
    end
    # Increase / decrease items
    $game_party.gain_item(changed_item, value)
    # Continue
    return true
  end


Anyway, I haven't tested, so I may have missed something, but try that.
Title: Re: Using Messages in RGSS
Post by: Zethzune on January 01, 2009, 02:38:48 PM
Thanks  ;D
I'll try that

[spoiler]Edit: That seems to work, at least when I replace the message with plain text. It doesn't seem to like the concatenated string. Maybe if I converted $data_items[changed_item].name into a string before I tried to use it?

Nope, that didn't seem to work.
I'm still getting a syntax error here on like 227, am I not using the right operator for string concatenation? Some languages are & or &&, but I can't seem to find anything definitive in the RMXP help file.

Edit Again: Actually it seems to be the color codes that are making it temperamental. I think RGSS is trying to use the escaped color codes as variables - how you can put a variable in a string in some languages by escaping it - because it seems to work fine without the color codes.
Maybe I'll just go hack the window_message to use different formatting for the colors.

Another problem here if anyone has any ideas: Now that I have the messages, they don't ever go away. It took a lot of detective work to figure out that setting the message to != nil called it, but I can't seem to figure out how to uncall it the way the events do. (This was resolved, for some reason the messages started uncalling automatically  ???)

Edit Yet Again: Oh my bad. If I escape the escape there isn't any need to edit the escape. Now that nobody knows what I'm talking about:

Edit Yet Again:
It turns out the messages aren't auto uncalling. It still gets stuck in a loop popping up the message; but it just so happens with the event I tested this with there was a second message in the event code - which was properly disposing - ending the cycle.[/spoiler]
Title: Re: Using Messages in RGSS
Post by: Zethzune on January 01, 2009, 09:59:33 PM
Okay this all works except the message system gets stuck in a loop and keeps displaying the message every time you press Space/Enter/C. If there is a message in the Event after the change items it calls that - after the message from the event is displayed the loop ends.

I can't figure out how to end the loop otherwise.


  def command_126
    # Get value to operate
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    # Increase / decrease items
    changed_item = @parameters[0]
    if value > 0
      if value != 1
        $game_temp.message_text = "You gained \\C[1]" + value.to_s + " " + $data_items[changed_item].name + "\\C[0]!"
      else
        $game_temp.message_text = "You gained \\C[1]" + $data_items[changed_item].name + "\\C[0]!"
      end
    elsif value < 0
      if value != -1
        $game_temp.message_text = "You lost \\C[1]" + value.to_s + " " + $data_items[changed_item].name + "\\C[0]!"
      else
        $game_temp.message_text = "You lost \\C[0]" + $data_items[changed_item].name + "\\C[0]!"
      end
    end
    $game_party.gain_item(@parameters[0], value)
    # Continue
    return true
  end
Title: Re: Using Messages in RGSS
Post by: modern algebra on January 01, 2009, 10:39:20 PM
Well, add this:


    # Set message end waiting flag and callback
    @message_waiting = true
    $game_temp.message_proc = Proc.new { @message_waiting = false }

before the message setting. - Make sure to do so only when you are setting a message though. Hopefully that will work.
Title: Re: Using Messages in RGSS
Post by: Zethzune on January 02, 2009, 05:48:40 PM
Thanks that worked - Well I think it did, I only tested it one place, but it seemed to work as advertised.

I inserted it above the If statement because there's no way it can go through my If without sending a message.
Title: Re: Using Messages in RGSS
Post by: modern algebra on January 03, 2009, 10:37:03 PM
For the one that you posted before there is. if value == 0 it will go through without sending a message.

It won't be common, but it's possible