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

I see along of script errors lately during my massive debbuging process this weekend and helping others.

Here is a few tips I learned.

1. Don't add scripts and then load a continue or saved game. It holds old variables that didn't have the new script involved. Always start fresh when adding or changin scripts.

2. Sometimes moving added/or custom scripts around in the script editor can solve the issue. That happened to me with XL-core and Symphony. When I moved Xl- Core above everything even symphony it stopped the error. Weird but true.

3. When Debuging and asking for help, a pic or snapshot of the error box is a big big help. 99% of the time it's the last new script you added.

These are a few tips.
3. When Debuging and asking for help, a pic or snapshot of the error box is a big big help. 99% of the time it's the last new script you added.
AND TELL PEOPLE what scripts you're using AND provide links.
Moving scripts around usually only works when one overwrites stuff and the other simply adds onto it.


Order of execution is important if one script depends on the other, if you put scripts above its pre-requisites, probably not going to work, especially if the code first checks "if prequisite is imported..."


If both scripts overwrite the same method, you're pretty much out of luck; you'd have to actually go in and combine the conflicting methods manually so that all of the logic is retained.


I have attempted to contain all of the logic for any overwritten methods within a single line so others can just copy that one line into the conflicting scripts.
I'm getting an error when I try to use the following script call:
 
$game_variables[50][this.id] += 5

undefined method '+' for nil:NilClassor
$game_variables[50][self.id] += 5

undefined method 'id' for#<Game_Interpreter:blabla>I believe 'this' was an addon for a script I commissioned from Enelvon that allowed me to use 'this.id' to get the current events ID.
In both cases, it should have ended up translating to $game_variables[50][20] += 5, which works fine if I called it just like that.
 
edit:
the == operator works perfectly fine in both cases
$game_variables[50][this.id] == 5
 
edit 2 solution:
 
Got it, Zal explained it to me. Since I didn't initialize the whole array to zeros it was still at 'nil' which can only take == or =.

Code:
$game_variables[50][this.id] == nil ? $game_variables[50][this.id] = 0 : nil$game_variables[50][this.id] += 5
Hey is it possible to check what terrain tag (set in the tileset in the database) the player is on? 

I'm trying to create a script that will automatically disable dash while walking through water, and I think I have most of it figured out, but the only way I've been able to find to check terrain tags is with events.
Try:


$game_map.terrain_tag($game_player.x, $game_player.y)
That worked perfectly, thanks!
This might have been asked before or was probably had its solution but I just want to ask for sure.

Is there a way to bypass / change the smooth scrolling of XP aside from adjusting it to smooth scroll mode? It only works for those with good end computers. In as much as I want my game to be played in its full potential graphics even in low computers, how can I activate a better smooth scrolling through a script? I only saw something for VX but for XP....I am lost in thought.
I was just wondering (and I hope this is the right place to ask this) is there a script call that I can use to check how many actors are in the current party? I have been looking all over for this because I want to limit the overall party (not just battle party) to just 4 actors and will be needing to check how many actors are already in the party during my game. I know I could do this with variables but If there is a script call that can do this (or even any other way that I haven't been able to find) it would make this part of my game so much easier.
$game_party.members.size will give you the number of battlers if you're in battle, but the total number of members (battlers and reserve) at all other times.


However, you can also get this via Control Variables > Game Data > Other > Party Members, so you really don't need to use a script call if you're already in an event.
Thanks Shaz 😀 . I think I might of seen that script call somewhere else while looking for this solution but I didn't understand the whole thing about it being everyone when used outside of battle. Also thanks for telling me about the event method I feel so silly for not seeing that before.
Does anyone happen to know how the Input module will only get a key once every second, based on the game's frame rate, so that it doesn't always grab a key press? I assume it's something done in the update method, but I'm not entirely sure what it is. I've tried making a counter to only work every 60 updates, but it didn't work out as well as I had hoped.
It would be difficult - you might need to experiment between Input.press? trigger? and repeat? because if you're only checking once every 60 frames, the method you're using might require the button to be pressed exactly on that 60th frame.

Basing it on frame rate might be incorrect too, because you'd have to guarantee that your game would always run at that frame rate, and if you have anything that causes lag, or the player has an older computer that can't handle that frame rate, both of those will cause issues.

A new method like this might be a good starting point, but would be prone to the issues just mentioned:

Code:
module Input  def press_60?(sym)    press?(sym) && Graphics.frame_count % Graphics.frame_rate == 0  endend
Oh, no, I wasn't extending the Input module, I'm trying to replicate the behavior that it won't get get input at every frame (because, ideally, the game will run too fast and that would be difficult to control). How I did it was just make a timer, which was defined as:

def self.update # It was in a module, so I can't use instance methods [email protected]_a?(Numeric) || @counter < 0 @counter = Graphics.frame_rate end if @count <= 0 @updated = true end @counter -= 1endWhen I did a specific function, @updated was set to false and no other input bits would be accepted until @updated was true again, but it seemed to run much too slowly, especially compared to the speed of the regular Input module, so I'm trying to figure out how it waits for a second (or however long it is) until it will get another key, or in my case, allow another action to occur.
Does your method really say if @count <= 0? You've used @counter everywhere else.


Game_Interpreter calculates play time (in seconds) as Graphics.frame_count / Graphics.frame_rate if that helps. You could get play time into one variable, then in your loop check if the current play time is different to the previous play time, which means a second has elapsed (and then save the current play time into the variable for the previous play time).
Oh, no, I wasn't extending the Input module, I'm trying to replicate the behavior that it won't get get input at every frame (because, ideally, the game will run too fast and that would be difficult to control). How I did it was just make a timer, which was defined as:

def self.update # It was in a module, so I can't use instance methods
Don't change Input.update. Write your own listener somewhere else.

You are asking for trouble if you're going to change how Input functions everywhere.

Have something in the scene check every few frames for example.
Does your method really say if @count <= 0? You've used @counter everywhere else.

Game_Interpreter calculates play time (in seconds) as Graphics.frame_count / Graphics.frame_rate if that helps. You could get play time into one variable, then in your loop check if the current play time is different to the previous play time, which means a second has elapsed (and then save the current play time into the variable for the previous play time).
No that was a typo on my retyping it.

Don't change Input.update. Write your own listener somewhere else.

You are asking for trouble if you're going to change how Input functions everywhere.

Have something in the scene check every few frames for example.
I am not rewriting anything about the Input module. It's for something apart from Input,  I'm trying to replicate it's update.
It was in a module, so I can't use instance method

--> Then why use a module? use classes instead
What would making it a class change? I don't need it as an object, that would actually make it more difficult to do this specific function. I just noted that it was a module for additional information, in case it was relevant.
Just so that you can use instance methods... if you really need it... but it seems you don't...

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