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

sokita

Crawling back to the surface
Veteran
Joined
Apr 27, 2014
Messages
198
Reaction score
29
First Language
Indonesian
Primarily Uses
['A', 'B', 'C', 'D'].each do {|switch| $game_self_switches[[map_id, id, switch]] = false

Assuming you're replacing map_id and id with actual numbers, because they would not work in a script call. You'd have to use $game_map.map_id and @event_id for the "current" event.
Actually, he/she can use

['A','B','C','D'].each{|ss|$game_self_switches[[@map_id, @event_id, ss]]}if he/she wants it shorter
Thank you Shaz and KockaAdmiralac_FINALLY! Yes, I usually using @map_id to represent current map id. What I want to achieve is makes all stone at a cave back to its shape after being destroyed. I am currently making mining game.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,144
Reaction score
12,418
First Language
English
Primarily Uses
RMMV
You might be better off grabbing one of the tile swapping scripts around. Using lots of events to cover a large area could cause lag issues. See how it goes, but that's an alternative for you if you find it's affecting performance.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
570
Reaction score
157
First Language
Serbian
Primarily Uses
N/A
@Rikifive

I don't know why it isn't working. I tried this code :

class Scene_Test < Scene_Base  def start    super    @window = Window_Test.new.show.activate    @window.set_handler:)ok, method:)on_ok))  end  def on_ok    p @window.active    @window.activate    p @window.active  endend class Window_Test < Window_Selectable  def initialize    super(0, 0, 100, 100)  endend
This code logs to the console the active state of a window.

On the other hand, what error is thrown when you try @actor_window.active    ?

Is @actor_window defined?
 

sokita

Crawling back to the surface
Veteran
Joined
Apr 27, 2014
Messages
198
Reaction score
29
First Language
Indonesian
Primarily Uses
You might be better off grabbing one of the tile swapping scripts around. Using lots of events to cover a large area could cause lag issues. See how it goes, but that's an alternative for you if you find it's affecting performance.
Actually, I am about to join a contest that prohibits me using custom script. Maybe later if I want to continue to work with the game. Maybe I'll break the mine into parts or limiting stones that can be destroyed. Thanks again Shaz.
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,442
Reaction score
679
First Language
Polish
Primarily Uses
Other
@KockaAdmiralac_FINALLY
When I tried:

class Sprite_Cursor < Sprite(...) def initialize(viewport = nil , x , y) (...) if SceneManager.scene_is?(Scene_Menu) if @actor_window.active @c_p = [-@cw + CURSOR_POSITION[0] + 180,CURSOR_POSITION[1]] #RIGHT else @c_p = [-@cw + CURSOR_POSITION[0],CURSOR_POSITION[1]] # LEFT end else @c_p = [-@cw + CURSOR_POSITION[0],CURSOR_POSITION[1]] # LEFT end(...)it threw that on me upon opening main menu:

--------------------------------------------------------------
Did I do something wrong?
 

There is more info about my problem:
The problem is that, the status window in near the left border, and the cursor goes off (completely), which is weird, so I'd like to make it to be on the right side when going to party window. If it's impossible, then it's fine, I'll find a workaround for it.
Here is how it looks: (don't mind the mess)

Here's the script.
and my part, where it changes position:
  
Code:
class Sprite_Cursor < Sprite    include MOG_MENU_CURSOR    #--------------------------------------------------------------------------  # ● Initialize  #--------------------------------------------------------------------------      def initialize(viewport = nil , x , y)      super(viewport)      @cursor_image = Cache.system($game_system.menu_cursor_name.to_s)      @frame_max = (@cursor_image.width / @cursor_image.height) rescue 1      @frame_range = @frame_max > 0 ? (@cursor_image.width  / @frame_max) : 1      @frame = 0 ; @ca_speed = CURSOR_ANIMATION_SPEED      self.bitmap = Bitmap.new(@frame_range,@frame_range)      self.z = 10000 ; self.opacity = 0 ; @cw = self.bitmap.width / 2        if SceneManager.scene_is?(Scene_Menu) && @actor_window < HERE IT STARTS          @c_p = [-@cw + CURSOR_POSITION[0] + 180,CURSOR_POSITION[1]] < RIGHTY        else          @c_p = [-@cw + CURSOR_POSITION[0],CURSOR_POSITION[1]] < LEFTY        end      @mx = [0,0,0] ; refresh_animation(true) ; update_move  end(...) rest of script
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,696
Reaction score
3,005
First Language
Tagalog
Primarily Uses
RMVXA
That should gp into its own thread I think because you are now having a problem with a certain script...
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,442
Reaction score
679
First Language
Polish
Primarily Uses
Other
Perhaps, but I thought the answer will be just: 'Yes it is possible, use <some stuff>' or 'it's not possible' =P
Well... Anyway you're right ~ For now I'll leave it be here and wait for @KockaAdmiralac_FINALLY, perhaps he'll know the answer ~ if not, then I'll move it to its own thread and stop spamming here.

 

SOLVED.
 
Last edited by a moderator:

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
570
Reaction score
157
First Language
Serbian
Primarily Uses
N/A
Are you sure you solved it?

Because I don't know if you understood the hierarchy of the displaying objects...

The main object that can display something is Bitmap.

Window is a Bitmap with windowskin, and Sprite is also a Bitmap, with it's own specifications.

Scenes are the controllers of Windows and Sprites.

But from a Sprite you can't control a Window, nor reverse (at least not USUALLY)

You placed @actor_window in the mouse SPRITE.

But, that Sprite is controlled by the Scene (in this case, Scene_Menu), and that Sprite has really no idea what Windows are.

So, you must put your code in the object that knows what are Sprites and what are Windows, and that is SCENE (in this case, Scene_Menu)

 

So, if you want to constantly check what window is active, you can do something like following : 

Code:
class Scene_Menu < Scene_Base  alias :rikifive_random_alias_update_1Mp0 :update  # This method below is called upon initializing, that means, @actor_window is defined, but on every 1/60 of a second  # This may not be a good idea to put this code here, since it may bug up the whole scene, but I did not read the whole script,   # so I don't know which method is better for putting this in. Maybe you can find out.  def update    rikifive_random_alias_update_1Mp0    if @actor_window.active      # Here, control the Sprite    else      # Some more controlling    end  endend
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
21,864
Reaction score
11,071
First Language
English
Primarily Uses
RMVXA
@KockaAdmiralac_FINALLY

If your internet stutters resulting in a double posting of the same thing, then just report your second post (the Report button is bottom right, near the Multiquote button) and ask the mod for this forum to delete it for you.
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,442
Reaction score
679
First Language
Polish
Primarily Uses
Other
@KockaAdmiralac_FINALLY I'm not sure if it's solved solved, but it's at least solved. =]

By that I mean ~ there is this

def update_cursor_position return if !can_update_cursor_position? x_v = [0,0] if SceneManager.scene_is?(Scene_Battle) x_v = [-self.viewport.ox, self.viewport.rect.y] if self.viewport != nil end x_e = (self.cursor_rect.x + self.x) - self.ox $game_temp.menu_cursor[1] = 2 ; $game_temp.menu_cursor[2] = x_e + x_v[0] y_e = (self.cursor_rect.y + self.y + self.cursor_rect.height / 2) - self.oy $game_temp.menu_cursor[3] = y_e + x_v[1] end
replaced with this:

def update_cursor_position return if !can_update_cursor_position? x_v = [0,0] if SceneManager.scene_is?(Scene_Battle) if self.viewport != nil x_v = [-self.viewport.ox, self.viewport.rect.y] end end x_e = (self.cursor_rect.x + self.x) - self.ox if self.class == Window_MenuStatus x_e += self.width - 24 + 200 end $game_temp.menu_cursor[2] = x_e + x_v[0] y_e = (self.cursor_rect.y + self.y + self.cursor_rect.height / 2) - self.oy $game_temp.menu_cursor[3] = y_e + x_v[1] $game_temp.menu_cursor[1] = 2 end
and it works.

I'm not sure what to do with your code though, I pasted that below that script and it crashed upon launching game. =P
 
Last edited by a moderator:

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
570
Reaction score
157
First Language
Serbian
Primarily Uses
N/A
@Rikifive : My code isn't made for usage, it's made for demonstration purposes, so I'm not surprised that it does not work.

@ksjp17 : Oh, I didn't know that, thanks. I reported both posts now.
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,442
Reaction score
679
First Language
Polish
Primarily Uses
Other
KockaAdmiralac_FINALLY Hahaha my bad! xD

So if you don't have any objections about current solution, then it's solved. =]

Thank you for your time and helping me! =]
 
Last edited by a moderator:

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,442
Reaction score
679
First Language
Polish
Primarily Uses
Other
I feel so stupid for asking this, but hey, I'm still learning.

Question: How to use '>' '<' etc. in 'case'?

Example: When using condition 'if' I can put for example 'if $game_variables[1] <= 7' how to translate '<=' to be able to use that in 'case' ~> 'when'?

case $game_variables[1] when <= 7 <<< translate 7! when 8 8! when >= 9 <<< translate 9!end What I'm trying to achieve:  Well... If certain variable is less or equal 7 , then it does one thing; when it's equal 8 - does second thing; when it's 9 or more then does third thing.

Thank you in advance.
 

sokita

Crawling back to the surface
Veteran
Joined
Apr 27, 2014
Messages
198
Reaction score
29
First Language
Indonesian
Primarily Uses
a = $game_variables[1]case awhen a >= 7#do_somethingwhen a <= 8#do_something_elseelse#don't do somethingendLike that, right?
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,442
Reaction score
679
First Language
Polish
Primarily Uses
Other
It doesn't read "when's" with '<' '>' at all.
I did that

a = $game_variables[1] case a when a <= 7 7! <<< actually does nothing when a = 8 8! < it works when a >= 9 9! <<< actually does nothing end 

Nvm. I figured it out.
 
ANSWER: just putting '..'

case $game_variables[1] when 0..7 7! when 8 8! when 9..99~ 9!end That's all, thanks for trying though.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,144
Reaction score
12,418
First Language
English
Primarily Uses
RMMV
Why did you put ! on the lines? ! doesn't do anything, and I'm a bit surprised it didn't give you an error. ! means not, but you use it before something, not after.

< means "is less than"

= means assign. == is compare. So you should have == 8, not = 8. a = 8 will always return true, because it will always succeed in changing the value of a to 8.

You don't say case a and then when a < 3

Anyway - here's the correct syntax for what you're trying to do.

Try this:

case $game_variables[1] when 0..7 7 when 8 8 else 9endYou know, you could also look this up in the help file. F1 and go to Search, then type in Case. It's under Control Structures and it gives you an example.
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,442
Reaction score
679
First Language
Polish
Primarily Uses
Other
Ninja'd =P

the 7!; 8!; 9! are just examples, it doesn't mean anything here, I just wanted to state it should be 7! here 8! here etc. I know it'd not work.

The question was just about using these <>.

I found the asnwer in the base scripts. =]

Thank you for replying anyway, sorry I didn't find that sooner.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
570
Reaction score
157
First Language
Serbian
Primarily Uses
N/A
I actually more use ?: operator

b = a <= 7 ? 7 : a == 8 ? 8 : 9This code does that b is 7 when a is less than 7, b is 8 when a is 8 and b is 9 when a is greater than or equal to 9
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,144
Reaction score
12,418
First Language
English
Primarily Uses
RMMV
Which is nice if you're comfortable enough with scripts to understand what that means. For a beginner, something less compact but easier to understand is better.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
570
Reaction score
157
First Language
Serbian
Primarily Uses
N/A
Yeah, you're right.

But still does not mean that they don't need to learn what ?: is.

I found myself editing my older scripts with this just to compress the code, so I think maybe someday the great scripter Rikifive would look at his old scripts and say :

"What did I do with case and when when I could just do this with one ?: operator???"

So that's why I mentioned ?: operator
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

I'm back to the bugs.
100 bugs in my coding,
take one down,
fix it up,
132 bugs in my coding.
On the plus side, if all this rioting sparks another Covid outbreak... I will have a whole lot of time to work on my game. Not exactly how I wanted to get that time, but hey I'm a glass is half full... of RM kind of guy. :LZSwink:
A video once in a while won't hurt.
Have a craving for a Nesquik milkshake. No idea why. Haven't had one since I was a kid. lol. I remember them kinda tasting nice, but also leaving a lot of nasty powder at the bottom of the cup.

Forum statistics

Threads
98,071
Messages
949,021
Members
129,342
Latest member
Cylria
Top