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

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
The update method itself is a "loop", you don't need another loop.

Here is an example from one of my scripts:

@counter += 1 # Adding 1 to the counter each frame. if @counter >= @effs[@phase] # A variable to check against the counter. case @phase # Checking the current phase. when :start do_starting_phase # This runs when the counter reaches 0 the first time. @phase = :idle # Setting the next phase. when :idle do_idle_phase # This runs when the counter reaches 0. Got a different phase. @phase = :end # Setting the next phase. when :end do_ending_phase # Runs when the counter reaches 0. Yet another phase. @phase = :dispose # Setting the next phase. end @counter = 0 # Resetting the counter each time at the end. end
This whole thing is inserted in the update method.

Let's see what's happening here...

First, the @counter is initialized with a value of 0.

The @phase is another variable which decides what will be run when the counter condition is true. This way you can use a single counter and make separate stuffs happen depending on another variable. Optional part, but useful for making many things happen based on the value of this variable.

The @effs[@phase] is a hash, which lets you make infinite phases by simply adding new keys and setting their value to an integer. This way you can make separate countdowns for each of your phases. Completely optional, this can simply be a static number if you don't need different timing for different stuffs on the scene.

In the update method, the @counter is incremented by 1 on each frame.

In every frame, there is a condition which checks if the counter has reached a specific value or not.

If it did, it runs a method based on the current @phase and sets the next phase accordingly.

At the end, still in the condition check, the @counter is reset to 0, so it can start to count again until it reaches the next phase time.

Now that you got this, you can insert different methods into the update method.

These methods would only run when the counter reached the defined value.

No idea what are you trying to do, but whatever it is, if it needs timing, you need to meddle in the update method directly, and make your conditions in it cleverly, so that the methods in the update method run only when you want them to.
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,441
Reaction score
680
First Language
Polish
Primarily Uses
Other
Hmm.. So when using 'update' method I could do this:

def update @wait_time += 1 if @timer # is true if @wait_time == 180 do_stuff @timer = false @wait_time = 0 end #(... and there is some other stuff ...)def do_stuff #do stuff I wantenddef player_did_something SOME-SE.play @timer = trueendWould that be good enough?

And still it's way more complex than it should be. I can't believe there's no such ha thing by default.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
Yeah, you can do that, it should work.


It's not really complex actually, you just create a condition for your method based on a timer.


Effectively, it's the same like that event conditional branch with the timer (used in eventing), the only difference is that you needed to make your own timer here.


You can try to see how the interpreter does it, but since it uses a Fiber, I never really bothered with it. I just hate Fibers. :p
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,441
Reaction score
680
First Language
Polish
Primarily Uses
Other
Yeah, it's not that complex, since it just uses logic. ~ But I thought it'll be much simpler/shorter and not involving making stuff all over the place. =P

I tried to look how the interpreter does it, but I got that Fiber error and stopped on that. =P

Oh, and I nearly forgot - Thank you both for your time of course.

*and again - a simple question turned out into a huge spam on this thread ~ sorry*
 
Last edited by a moderator:

Torqus

Veteran
Veteran
Joined
Aug 2, 2015
Messages
169
Reaction score
26
First Language
English
Primarily Uses
Hello again everyone, I didn't want to post here again but I'm stuck.

I'm trying to modify Scene_Base to have one font for the Menu, and other font for the rest of the game, that's because I want a pretty font for menu and a legible font for story telling.

I already made the method to change the font:

def change_font_modded if !SceneManager.scene_is?(Scene_Map) Font.default_name = "Motion Control" end endi think it changes the font when the Scene isn't map. But clearly I'm missing something because no mather where I put the "change_font_modded" it doesn't work.
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,441
Reaction score
680
First Language
Polish
Primarily Uses
Other
Hmm.. I'm changing fonts by editing the windows themselves ~ more or less. =P

I'm not sure how to help with that code. =P
 

Torqus

Veteran
Veteran
Joined
Aug 2, 2015
Messages
169
Reaction score
26
First Language
English
Primarily Uses
I'm thinking maybe I can make:

def change_font_modded Font.default_name = "Motion Control" endAnd add "change_font_modded" in every Scene_X

I'll test that.

EDIT:

Nah, I can do that. But I as soon as I leave a Scene that changes the font, that font will still be there.

That's because I don't tell the game to change font when the Scene is closed.

I tried making a "change_font_back" with the same as "change_font_modded" with another font, but still, I don't know where to put "change_font_back" to be processed when the player is in the map.
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
You can add this snippet to make what you want:

class Scene_Base alias change_emfonts8865 start def start if SceneManager.scene_is?(Scene_Map) Font.default_name = ["Gabriola","Verdana"] # Font for the map. else Font.default_name = ["Morpheus","Arial"] # Font for any other scene. end change_emfonts8865 end end
Put this on the top of your custom script list.

Use an array of font names instead of a single string.

The start method runs every time the scene changes, so it's the ideal place to do what you want.
 

Torqus

Veteran
Veteran
Joined
Aug 2, 2015
Messages
169
Reaction score
26
First Language
English
Primarily Uses
Wow It was that simple, I just didn't know how to... "auto-start" the code, so that's how you do it then. Thank you.

EDIT:

Use an array of font names instead of a single string.
Why? I have a custom font in Fonts folder, why should I assign a secondary font as reserve?
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
If you provide the font, than you don't need to.


Thou, it's more of a habit for me than safety. :p
 

cremnophobia

Veteran
Veteran
Joined
Dec 10, 2013
Messages
216
Reaction score
97
Primarily Uses
Why? I have a custom font in Fonts folder, why should I assign a secondary font as reserve?
Exactly. There's no good reason to use this feature. Just think of all the work you have to do to make sure you don't have squeezed or cut-off text with any of the specified fonts.
 

Torqus

Veteran
Veteran
Joined
Aug 2, 2015
Messages
169
Reaction score
26
First Language
English
Primarily Uses
Exactly. There's no good reason to use this feature. Just think of all the work you have to do to make sure you don't have squeezed or cut-off text with any of the specified fonts.
It's ok, he mentioned it because I didn't say I had a custom font. If I hadn't one, the correct thing would be to have multiple fonts so if the player's pc doesn't have one, the game can use other instead.

Also...

Is it okay if I write:

if SceneManager.scene_is?(Scene_Map) or SceneManager.scene_is?(Scene_Status) or SceneManager.scene_is?(Scene_items)I see it's working, I just want to be sure it's not going to lag my game for some reason.

EDIT: Forget it, I found a thread where Shaz said it was ok.

EDIT 2:

Hey guys, I edited this "Change font" script so now I can define font color for each scene. I couldn't understand the "self.contents.font.color" and all that. What do you think?

Code:
class Window_Base  #---------------------------------------------------------------#   DEFINE NEW COLORS#---------------------------------------------------------------  def map_color;         Color.new(255,255,255,255);  end;    # TP gauge 1  def menu_color;        Color.new(255,200,0,255); end;   # TP gauge 2  def battle_color;      Color.new(0,200,200,255); end;   # TP cost    #---------------------------------------------------------------#   TELL WHICH SCENE TAKES THE COLOR#---------------------------------------------------------------  def normal_color    if SceneManager.scene_is?(Scene_Map) or SceneManager.scene_is?(Scene_Quest) or SceneManager.scene_is?(Scene_Status)     return map_color    elsif SceneManager.scene_is?(Scene_Battle)     return battle_color    else     return menu_color    end  endend#---------------------------------------------------------------#   THE CHANGE FONT SCRIPT#---------------------------------------------------------------class Scene_Base  alias change_fonts start  def start    if SceneManager.scene_is?(Scene_Map) or SceneManager.scene_is?(Scene_Quest) or SceneManager.scene_is?(Scene_Status)      Font.default_name = ["Roboto"]      Font.default_size = 20      Font.default_outline = false          elsif SceneManager.scene_is?(Scene_Battle)      Font.default_name = ["Motion Control"]      Font.default_size = 19      Font.default_outline = true          else      Font.default_name = ["MLP - Magic is Friendship", "Equestria", "Cartoonist"]      Font.default_size = 16      Font.default_outline = true    end    change_fonts  end  end
 
Last edited by a moderator:
Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
In an event, if I use "Set Move Route", I can click "Wait for completion" to pause the script until the event has completed it's movement to the next tile. Is there a script equivalent for this?
I.E., I can script "move toward player" with "wait for completion" checked, and I know the script equivaletn is basically "ThisEvent.move_toward_character(Player)", yet I don't know what to script for the "wait for completion" part.
 

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,254
Reaction score
611
First Language
English
Primarily Uses
I'm looking for a way to change the "Z" level of an event. I believe it's currently calculated by @priority_type * 100.

I could of course change the priority type, but the problem here is that I need it to act as if it's priority_type 1 but look like priority_type 0 (Same as Character, Below Character, respectively).

Any help here would be greatly appreciated!
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
I'm trying to figure out how to access state information from the variable @subject in Scene_Battle. Doing @subject.states gives an undefined method states for <Game_Actor>. However doing an @subject.inspect shows @states as being one of the variables that can be accessed. So then what am I missing?

Thanks for any help on this.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
There is a method with the name 'states' in 'Game_BattlerBase', so it should be impossible to get a NoMethod error by calling '@subject.states' unless you deleted that method.

Are you sure it's for 'Game_Actor' and not for a nil class? Since '@subject' can be nil during the battle, getting a NoMethod error for calling 'states' on a nil class is possible.

@seita

Here, a snippet which can change the Z value of events:

class Game_CharacterBase alias custom_event_z8876 screen_z def screen_z if self.is_a?(Game_Event) && @event.name =~ /<custom_z: (\d+)>/i return $1.to_i else return custom_event_z8876 end end end
Just enter <custom_z: value> for the name of the event, where value will be the Z value of the event.
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
Your right it was actually how I was using it that was the cause of the error. Thanks Sixth. ;)
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Is there a way to cancel an actor's action when his/her target is already dead? For example, Eric should use a skill to Slime A but then Natalie killed Slime A before he does. Normally, Eric would still perform the skill to any remaining target. Is there a way of a script to cancel Eric's action since Slime A is dead?
 

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,254
Reaction score
611
First Language
English
Primarily Uses
Thanks @Sixth! I modified it a bit to read from a comment instead of the event name. Works perfectly!
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
@Milena

I don't remember where is the skill/item usage triggered, but find that, and you can add a 'target.dead?' check for the method, and do something else if the target is dead already (like do nothing, for example).
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Posts

Latest Profile Posts

This is relevant so much I can't even!
Frostorm wrote on Featherbrain's profile.
Hey, so what species are your raptors? Any of these?
... so here's my main characters running around inside "Headspace", a place people use as a safe place away from anxious/panic related thinking.
Stream will be live shortly! I will be doing some music tonight! Feel free to drop by!
Made transition effects for going inside or outside using zoom, pixi filter, and a shutter effect

Forum statistics

Threads
105,998
Messages
1,018,218
Members
137,777
Latest member
Bripah
Top