QuietlySilver

Broke PhD student thriving on a $5.00 bank account
Member
Joined
Jul 29, 2018
Messages
10
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Hello! This is my first thread on the forum, so I apologize if I've incorrectly categorized/posted anything beneath the wrong section - I usually attempt to solve my own errors, so I've never done this before, ha.

I'm currently working on a custom main menu, and I've been held up by a conditional issue. I've implemented a "skip title processing" command to instead create my own introductory sequence and main menu with custom options (for both aesthetic purposes and so I can expand upon the default menu options - Start, Continue, Exit - to add configuration, chapter replayability, and bonus content). Everything operates perfectly until I reach the conditional branch, wherein I want the player to be able to progress to the actual "main menu" I've created on the next map by pressing "Z"; otherwise ("else"), the introductory screen operates as "normal" - with the game logo as a parallax background and my "PRESS START BUTTON" message displayed as a picture, which "moves" between opacities to create a "flashing" effect.

Obviously, I want the player to be able to press "Z" at any time, so the process must be constantly checking if the condition has been met - otherwise the player has to randomly press "Z" during the same tiny millisecond that the condition is being checked, which is both nearly impossible and really stupid, ha. Pressing "Z" should meet the conditions for the next series of commands, wherein my "CONFIRM" sound effect plays, the "PRESS START BUTTON" flashes white, and the player is transferred to the actual main menu screen with choosable options.

I assume the issue arises in the loop I've also included - which is necessary to create the "flashing" effect for the "PRESS START BUTTON" message. I'd like to retain the "flashing" effect and I'm unsure of how to do so without the "loop" command; I don't want the "flashing" to lag/sputter/stop during the transition for the sake of quality. The event is currently activated via "autorun" and I've attempted "parallel process" as well - but neither trigger seems to work. There's likely a more efficient method and what I'm doing is needlessly complex, but I'm operating on three hours of sleep and I think my brain is rather sluggish at the moment; quarantine and college do not mix.

I've included screenshots of the event pages below:

Main_Menu_1.png

Main_Menu_2.png

TL;DR - basically, I want the player to be able to progress to the "next screen" by pressing a button without interrupting the "flashing" message process.

Sorry for such a lengthy post! I'm always happy to provide clarification if my questions are confusing! :')
I'm just grateful for any bit of help. Thank you so much, and have a nice day!
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
37,918
Reaction score
10,508
First Language
German
Primarily Uses
RMMV
the break loop command can't work because it is outside your loop, it has no loop to break. What happens is that the self-switch on prevents the look from restarting.

if you handle the conditional branch inside the loop if should work as intended
 

QuietlySilver

Broke PhD student thriving on a $5.00 bank account
Member
Joined
Jul 29, 2018
Messages
10
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I've already attempted to place the conditional branch inside of the loop, but I've had no luck there, either. I tried again per your suggestion, but it still won't work. I've attached another screenshot just to ensure that I inserted the commands in the format you suggested! Sorry for being a handful ^^;

MainMenu_withBranchInsideLoop.png

I really appreciate your help! Thank you!
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,481
Reaction score
633
First Language
Italian
Primarily Uses
RMVXA
To be honest I do not think that your problem lies within the fact that you are unable to enter the conditional branch. The main issue there is that you have a lot of wait commands that prevent the conditional branch from running every frame. You are basically only checking for input once every 1.5 seconds.

This might prove to be a much better solution:
Code:
Variable X = 1
Loop
  if Z button is being pressed
    Self Switch A = ON
    Variable N = 0
    Break Loop
  end if
  Variable N += Variable X
  if Variable N % 15 == 0
    picture opacity = 250 - 50 * (Variable N / 15) # no wait here
    if Variable N >= 60 OR Variable N <= -60
      Variable X *= -1
    end if
  end if
Repeat Above

This checks if the button is being pressed each frame and, at the same time, allows you to change the picture opacity.I used picture opacity = 250 - 50 * (Variable N / 15), you might have to use conditional branches if you want to do it with event commands.
 

QuietlySilver

Broke PhD student thriving on a $5.00 bank account
Member
Joined
Jul 29, 2018
Messages
10
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Oh, I see! That coinciding press/check was actually an issue I worried about. I wasn't aware that the "wait" command would affect the conditional branch if it was within the branch itself - though in hindsight, that's rather obvious, oops. Thank you so much for the tip, and for taking the time to code my event with greater efficiency! I just have a couple of questions.

1. Does the "wait" command halt all background/parallel processes operating within the same map, or only those executed by the event that actually contains the acting "wait" command?

2. How do I implement the code you've written? Do I use a single script call for the entire code, or break it into pieces using conditional branches?

3. I've gone through and written the functions on each input line to help me practice Ruby. If I've interpreted anything incorrectly, please let me know!

Ruby:
Variable X = 1                                              # Line 1 - Assigns Variable X the value of "1"
Loop                                                        # Line 2 - Initiates the loop command
    if Z button is being pressed                            # Line 3 - Defines first "if" statement condition as "Z Button Being Pressed"
        Self Switch A = ON                                  # Line 4 - Activates "Self-Switch A" if the Z button is pressed
        Variable N = 0                                      # Line 5 - Assigns Variable N the value of "0" if the Z button is pressed
        Break Loop                                          # Line 6 - Breaks loop if the z button is pressed
    end if                                                  # Line 7 - Terminates first branch
Variable N += Variable X                                    # Line 8 - Assigns N the value of N plus X
    if Variable N % 15 == 0                                 # Line 9 - Defines second "if" statement condition as "if N is divisible by 15 [with a remainder of 0]"
            picture opacity = 250 - 50 * (Variable N / 15)  # Line 10 - Picture opacity is defined by 250 minus 50 times (N divided by 15) if N % 15 == 0
        if Variable N >= 60 OR Variable N <= -60            # Line 11 - Defines third "if" statement as "if N is greater than/equal to 60, or N is less than/equal to -60"
            Variable X *= -1                                # Line 12 - Assigns X the value of X times -1 if N >= 60 OR N <= -60
        end if                                              # Line 13 - Terminates third branch
    end if                                                  # Line 14 - Terminates second branch
Repeat Above                                                # Line 15 - Maintains loop command

4. How does "end if" differ from simply writing "end"? Is it just a preference?

5. Multiple "if" statements define a series of unrelated conditions and allow the execution of different outcomes because each of them are separate processes. Conversely, "if-else" and "if-elseif-else" statements check if one condition has been met and execute the corresponding single outcome out of several available. In the code you've provided, have you written three separate "if" statements? Or are any of the "if" expressions supposed to function as an "else"?

6. Math has never been my strong suit, so pardon my confusion, but - how can "Variable N" be used in the given formulas when it was never assigned an initial numerical value? Am I supposed to assign the value, or will "Variable N" operate correctly without a predefined value?

Again, thank you so much for your help! Sorry to bombard you with questions.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,481
Reaction score
633
First Language
Italian
Primarily Uses
RMVXA
1. Does the "wait" command halt all background/parallel processes operating within the same map, or only those executed by the event that actually contains the acting "wait" command?
It depends on how you set those other things. In particular, neither background animations nor parallel process events are halted when you loop a wait command.
The wait command simply tells the event how many frames have to pass before executing the new line, then the engine increases the counter each frame through the main loop and, when that counter reaches the limit you decided, it continues.

This means that only those things that happen in the same block during the main loop are halted. In particular, since parallel process events and animations are not part of the same block, they are not halted.

You can imagine it like this:
Code:
Main loop:
  update_animations
  update_parallel_process_events
  update_current_event
End main loop

The whole thing is a bit more complicated, but this should give you an idea of what goes on that is close enough to reality to allow you to properly set up your events.

How do I implement the code you've written? Do I use a single script call for the entire code, or break it into pieces using conditional branches?
The algorithm I wrote there is made using pseudo-code, no actual code has been used. I used pseudo-code to make it easier to understand and to help you to implement it using event commands. If you want to use an actual ruby script the syntax is slightly different.

The actual ruby code is this one:
Ruby:
var_x = id_of_the_variable_used_as_addend
var_n = id_of_the_variable_used_as_counter
pic_x = set_your_picture_x_coordinate_here
pic_y = set_your_picture_y_coordinate_here
pic_name = set_your_picture_name_here
pic_id = set your_picture_id_here
# Real code from here onward
$game_variables[var_x] = 1
screen.pictures[pic_id].show(pic_name, 0, pic_x, pic_y, 1.0, 1.0, 255, 0)
loop do
  if Input.press?(:C)
    $game_self_switches[[$game_map.map_id, @event_id, 'A']] = true
    $game_variables[var_n] = 0
    $game_variables[var_x] = 0
    break
  end
  $game_variables[var_n] += $game_variables[var_x]
  if ($game_variables[var_n] % 15 == 0)
    screen.pictures[pic_id].move(0, pic_x, pic_y, 1.0, 1.0, 255 - $game_variables[n], 0, 15)
    if (($game_variables[var_n] <= -60) || ($game_variables[var_n] >= 60))
      $game_variables[var_x] *= -1
    end
  end
  wait(1)
end

If I did not make any mistake while typing the code here, this one should work.

I've gone through and written the functions on each input line to help me practice Ruby. If I've interpreted anything incorrectly, please let me know!
Your guess is correct, I see no mistakes in your comments.

How does "end if" differ from simply writing "end"? Is it just a preference?
In pseudo-code it is easier to see whether or not an end statement refers to an if or to a loop if you append the statement to it. When writing ruby code you should refrain from doing so (as in the code above, where I only used end).

In the code you've provided, have you written three separate "if" statements? Or are any of the "if" expressions supposed to function as an "else"?
It is up to you actually, it could be coded with an if/else branch as well. I used multiple if branches mostly because the first one contains a break condition, so everything else is not going to be executed if you enter it, so there was no need to use an else statement, but is going to work even if you put an else statement there.
Ruby:
if (Input.press?(:C)
  # reset variables and break the loop
else
  # do everything else
end
This code above also works.

Am I supposed to assign the value, or will "Variable N" operate correctly without a predefined value?
Each game variable is initialized with a starting value of 0 in RPG Maker, if you want to use them as counters you can simply start increasing them. If you want to use normal variables instead of the ones defined within the engine (namely one that you define), then you have to give it a starting value. In case of variable[X], since I needed a different value I had to set it to 1 before starting to use it.

Again, thank you so much for your help! Sorry to bombard you with questions.
There is no need to be sorry about that, I am pretty happy to help when interesting questions come out. As a matter of fact, feel free to ask more questions if you want to, I will try my best to satisfy your curiosity.
 

QuietlySilver

Broke PhD student thriving on a $5.00 bank account
Member
Joined
Jul 29, 2018
Messages
10
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Ah, you're so sweet!! I love it when people entertain my curiosity! I've just got such a strange brain when it comes to analyzing/processing concepts; if I don't understand why and how something happens, it simply won't make sense to me. When someone tells me that it just does or that's just how it works, I get really frustrated. I can't seem to fully grasp a subject unless I reach and comprehend the fundamental point of each of its layers. So really, thank you for your generous help and in-depth responses!! <3

Regarding your actual Ruby syntax - I've edited it slightly configure the variables and address errors popping up when the code is run.
To be clear, this is still a work in progress - I'm about to meet with my professor and slave over a paper. I'll keep tweaking once I'm free!

Ruby:
class Scene_CustomTitle < Game_Map

    # Intro Sequence
    # -----------------

    def introductory_sequence
        var_x = 1
        var_n = 2
        pic_x = 100
        pic_y = 300
        pic_name = "Menu_Intro_PressStart"
        pic_id = 1
        $game_variables[var_x] = 0
        $game_variables[var_n] = 0
        screen.pictures[pic_id].show(pic_name, 0, pic_x, pic_y, 1.0, 1.0, 255, 0)
        loop do
            if Input.press?(:C)
                $game_self_switches[[$game_map.map_id, @event_id, 'A']] = true
                $game_variables[var_n] = 0
                $game_variables[var_x] = 0
                break
            else
                $game_variables[var_n] += $game_variables[var_x]
                  if ($game_variables[var_n] % 15 == 0)
                    screen.pictures[pic_id].move(0, pic_x, pic_y, 1.0, 1.0, 255 - $game_variables[var_n], 0, 15)
                  end
                  if (($game_variables[var_n] <= -60) || ($game_variables[var_n] >= 60))
                    $game_variables[var_x] *= -1
                  end
            end
        wait(1)
        end
    end
end

I call the code using this command within the script event editor:

Ruby:
@instance_class = Scene_CustomTitle.new
@instance_class.introductory_sequence


Thank you for your help!
 
Last edited:

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,481
Reaction score
633
First Language
Italian
Primarily Uses
RMVXA
if I don't understand why and how something happens, it simply won't make sense to me.
Doesn't that apply to everybody? At least for me it is the same. Anyway, I am glad that you appreciated my explanation. Don't be afraid to ask more questions if there is still something that you do not understand.

I've edited it slightly configure the variables and address errors popping up when the code is run.
I recommend you to avoid using inheritance where it is not required. There are two main reasons for that:
  1. ruby favors duck typing over inheritance when possible;
  2. it uses much more memory and makes things extremely hard to understand when going back to the code after a while.
If you want to use an easier syntax and have more freedom with your script you can add that method to the Game_Interpreter class. It can be done like this:
Ruby:
class Game_Interpreter

    # Intro Sequence
    # -----------------

    def introductory_sequence
        var_x = 1
        var_n = 2
        pic_x = 100
        pic_y = 300
        pic_name = "Menu_Intro_PressStart"
        pic_id = 1
        $game_variables[var_x] = 0
        $game_variables[var_n] = 0
        screen.pictures[pic_id].show(pic_name, 0, pic_x, pic_y, 1.0, 1.0, 255, 0)
        loop do
            if Input.press?(:C)
                $game_self_switches[[$game_map.map_id, @event_id, 'A']] = true
                $game_variables[var_n] = 0
                $game_variables[var_x] = 0
                break
            else
                $game_variables[var_n] += $game_variables[var_x]
                  if ($game_variables[var_n] % 15 == 0)
                    screen.pictures[pic_id].move(0, pic_x, pic_y, 1.0, 1.0, 255 - $game_variables[var_n], 0, 15)
                  end
                  if (($game_variables[var_n] <= -60) || ($game_variables[var_n] >= 60))
                    $game_variables[var_x] *= -1
                  end
            end
        wait(1)
        end
    end
end

If you do it like this, the event interpreter (an instance of Game_Interpreter) already knows what that method is and you can simply call it using introductory_sequence in your event script box. No extra instances required, no extra memory consumption, no extra parameters initialized, and a whole bunch of other improvements.
 

QuietlySilver

Broke PhD student thriving on a $5.00 bank account
Member
Joined
Jul 29, 2018
Messages
10
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I see. I included the "introductory_sequence" method within my own script that I've been writing so it would act within my series of commands to create a custom title sequence. Is it better to split the scripts I've written between the pre-defined classes? I was keeping them together for the sake of organization, but if that causes issues, I can split them as you suggest.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,481
Reaction score
633
First Language
Italian
Primarily Uses
RMVXA
Is it better to split the scripts I've written between the pre-defined classes?
Not necessarily, you can always put them all together in a single class or, even better, in a module with its own namespace. How you do that is up to you, the core concept of my argumentation is that you should not use inheritance the way you did. Your class inherits from Game_Map, which means that your instance will have a lot of methods and attributes copied from that class, and those things are not needed in your script.

On top of it, since every event runs within an instance of Game_Interpreter, if you place that method withing Game_Interpreter, you are sure that you can have access to all the instance variables and methods normally accessible from events. If you put it somewhere else you have to access those variables ad methods differently. The "show picture" command, for example, cannot be used with just screen.pictures[pic_id].show, because the screen method is not defined in a brand new class. You have to use something like $game_map.screen (or something similar, I am unable to check if the one I used is the correct syntax). The same applies to @event_id, which is defined within Game_Interpreter, but not in another class. In this case you might have to pass it as a parameter from the script call itself.

My recommendation is to stick to the same good practice that applies to every Object-Oriented language: each class should provide methods for its tasks. In this case, since you are creating a method that is going to be used in an event, it is a good idea to let that very class (Game_Interpreter) handle it.

As I wrote at the beginning of this message, it still works even if you do not follow this convention, but in that case, when you have to change how events work, you have to go and change that class as well, and you have to remember which class it is. If you let Game_Interpreter handle it, you already know that you are going to change that class when changing events behavior, a simple global search for "class Game_Interpreter" will reveal all the scripts where you added something to it, making the code much easier to maintain.
 

QuietlySilver

Broke PhD student thriving on a $5.00 bank account
Member
Joined
Jul 29, 2018
Messages
10
Reaction score
1
First Language
English
Primarily Uses
RMVXA
That's a perfect explanation! Thank you so much.

I've done as you said, pasted the code into the Game_Interpreter class, and it functions correctly until the button itself appears. Now the game correctly checks for when I press "Z" (which is bound to :C), but the "PRESS START" graphic still doesn't flash. In fact, it disappears altogether.

I assume the variables/equations aren't functioning properly? I've been messing around with opacity values in a separate event to see which values provide the smoothest "fade" transition. The "fade" looks best with my graphics when in factors of 255, so 255 -> 204 -> 153 -> 102 -> 51 -> 102 -> 153 -> 204 and repeat. I'll admit once again that I'm utterly trash at math, so is there a way to form an equation to set the opacity to these numbers with corresponding variables?
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,481
Reaction score
633
First Language
Italian
Primarily Uses
RMVXA
My bad, there was one mistake in the first code you posted and I kept re-posting it normally without fixing the error.

Ruby:
var_x = id_of_the_variable_used_as_addend
var_n = id_of_the_variable_used_as_counter
pic_x = set_your_picture_x_coordinate_here
pic_y = set_your_picture_y_coordinate_here
pic_name = set_your_picture_name_here
pic_id = set your_picture_id_here
# Real code from here onward
$game_variables[var_x] = 1
This was the original code I wrote.

This is what you wrote:
Ruby:
def introductory_sequence
  var_x = 1
  var_n = 2
  pic_x = 100
  pic_y = 300
  pic_name = "Menu_Intro_PressStart"
  pic_id = 1
  $game_variables[var_x] = 0 # This is the mistake!

In the method $game_variables[var_x] is used to determine whether or not you have to increase or decrease your current opacity. If you set it to 0 (which is the neutral element in additions and subtractions) it simply does nothing. It has to be 1. Everything above the comment # Real code from here onward was meant for configuration, everything below that line was meant to be actual code.

I'll admit once again that I'm utterly trash at math, so is there a way to form an equation to set the opacity to these numbers with corresponding variables?
Once you fix that value this issue should be solved as well.
 

QuietlySilver

Broke PhD student thriving on a $5.00 bank account
Member
Joined
Jul 29, 2018
Messages
10
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Ah, sorry for that!! ^^; Not sure when or how I managed to put that value there, ugh.

Nonetheless, I hate to be this way, but even though that mistake was in my previous posts, I actually fixed it when implementing the code. The method I have defined within the Game_Interpreter is the one you provided originally, with minimal tweaks to fix small errors (which I included below in case my changes screwed anything up).

CHANGES:
Line 1436 - "no method error"; original code called $game_variables[n], changed to -> $game_variables[var_n]
Line 1441 - "unexpected end"; required an "end" after wait[1] for some reason? I had already ensured that the method, its loop, its branches, and the interpreter class had ended correctly, so I'm not sure what that was about.

This is the code I currently have within the editor:

Ruby:
def introductory_sequence
    var_x = 1
    var_n = 2
    pic_x = 100
    pic_y = 300
    pic_name = "Menu_Intro_PressStart"
    pic_id = 2
    $game_variables[var_x] = 1
    screen.pictures[pic_id].show(pic_name, 0, pic_x, pic_y, 1.0, 1.0, 255, 0)
    loop do
      if Input.press?(:C)
      $game_self_switches[[$game_map.map_id, @event_id, 'A']] = true
      $game_variables[var_n] = 0
      $game_variables[var_x] = 0
      break
      end
    $game_variables[var_n] += $game_variables[var_x]
      if ($game_variables[var_n] % 15 == 0)
        screen.pictures[pic_id].move(0, pic_x, pic_y, 1.0, 1.0, 255 - $game_variables[var_n], 0, 15)
      if (($game_variables[var_n] <= -60) || ($game_variables[var_n] >= 60))
        $game_variables[var_x] *= -1
      end
      end
    wait(1)
    end
  end
end

I've also provided screenshots for better context/visualization:

IntroductorySequence_1.pngIntroductorySequence_2.png

Thanks again for your help! <3
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,481
Reaction score
633
First Language
Italian
Primarily Uses
RMVXA
There was an issue with the zoom. I mistakenly assumed that the percentage value was passed as a float, but it was passed as an integer and then converted into a float. You can solve the issue using this code:
Ruby:
class Game_Interpreter
  #----------------------------------------------------------------------------
  # * Introductory Sequence
  #----------------------------------------------------------------------------
  def introductory_sequence
    var_x = 1
    var_n = 2
    pic_x = 100
    pic_y = 300
    pic_name = "Menu_Intro_PressStart"
    pic_id = 2
    speed = 1 # Set this to either 1, 2, or 3 to animate your picture faster
    $game_variables[var_x] = 1
    screen.pictures[pic_id].show(pic_name, 0, pic_x, pic_y, 100, 100, 255, 0)
    wait(1)
    i = 0
    loop do
      i += 1
      if Input.press?(:C)
        $game_self_switches[[$game_map.map_id, @event_id, 'A']] = true
        $game_variables[var_n] = 0
        $game_variables[var_x] = 0
        break
      end
      $game_variables[var_n] += $game_variables[var_x] * speed
      if ($game_variables[var_n] % 15 == 0)
        screen.pictures[pic_id].move(0, pic_x, pic_y, 100, 100, 255 - $game_variables[var_n], 0, 15)
        if (($game_variables[var_n] <= 0) || ($game_variables[var_n] >= 210))
          $game_variables[var_x] *= -1
        end
      end
      wait(1)
    end
  end # Introductory Sequence
end # end of Game_Interpreter class

I have also added a speed parameter to customize your picture's pulsation speed.
 

QuietlySilver

Broke PhD student thriving on a $5.00 bank account
Member
Joined
Jul 29, 2018
Messages
10
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Works like a charm!

Thank you for taking time out of your day to write a quick script for me, answer my questions, and work with me until my problem was solved! You're wonderful, and I appreciate your generosity! <3
 

Latest Threads

Latest Posts

Latest Profile Posts

I am supposed to be preparing to teach my students this afternoon and tomorrow morning about Refugees, Asylees, and Fraud/Misrepresentation and all I can think about is how to improve my Turn Order display. :stickytongue:
Try changing POV battle, near and far away like suikoden...
watercave2.jpg

diablofar.jpg

In the end I choose near over shoulder resembles RE4. Tight close window better. The correlation between battleback, monster style and battler should also be observed and merged.
Upgraded my avatar to be cuter.
When you look for several things for ages and then suddenly find it all at once.

Status.png
Status2.png
equip.png
I'm going to see if I can set up a triple booting setup. Windows for standard use & gaming, debian for linux development and manjaro for linux gaming, wine & proton use.

Forum statistics

Threads
129,703
Messages
1,204,423
Members
170,769
Latest member
ghostyen
Top