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

if @listselect.y != 200 && @listselect.y < 200
  @listselect.y += inc_y
elsif @listselect.y != 180 && @listselect.y < 180
  @listselect.y -= inc_y
end

The green colored part of the condition is useless combined with the purple, as when the y-coordinate is already less than 200, it can't be equal to 200 at the same time anyway. This is not an error though.

However, the turquise colored part is useless for the same reason. If the y-coordinate is already less than 180, this line is never reached since the green/purple condition also results in true. Since you want to reduce the y-coordinate, you probably wanted to check if the y-coordinate is greater than 180 instead.

And why would there be a different target when the sprite moves upwards than when it moves down? If you wanted to add hysteresis for any reason, you would probably have to prevent the sprite from oscillating once it reached y = 200.
Is there any pattern you are using with your drawing in your slot window? Because I see that some Y values are 22, some are 24, some are 26, etc...

I see that you are using the same y_inc variable, which makes me wonder how could that code even work...

More importantly...

This:

@listselect.y != 370 && @listselect.y < 370is the same as this:
Code:
@listselect.y < 370
It can't be equal 370 and smaller than 370 at the same time.Anyway, if you want something changed upon an actual button press, you are better off doing it in a separate method for each directions (in this case up and down), and attach the Input.trigger?🙂UP/😀OWN) check for it.

You set the direction variable, the y_inc variable, destination variable, etc in that method, and make the logic of when to start and stop in a separate method in the update itself, using the above set variables in the button trigger method.

That way you got a better organized and much likely more functional code with way less lines to look through.

For example:

Spoiler
def set_moving_pic if Input.trigger?🙂UP) @dir = -1 index = @slot_window.index - 1 index = @slot_window.item_max - 1 if index < 0 rect = @slot_window.item_rect(index) @dest = rect.y elsif Input.trigger?🙂DOWN) @dir = 1 index = @slot_window.index + 1 index = 0 if index > @slot_window.item_max - 1 rect = @slot_window.item_rect(index) @dest = rect.y end enddef move_pic if @dir != 0 @pic.y += 2 * @dir # <-- will either go up or down 2 pixels at each frame @dir = 0 if @pic.y == @dest # <-- will stop moving the sprite end end
This is just one example, and may or may not help in your specific case. This is usually how I handle dynamic moving of windows/sprites.
And why would there be a different target when the sprite moves upwards than when it moves down? If you wanted to add hysteresis for any reason, you would probably have to prevent the sprite from oscillating once it reached y = 200.
Thanks for the info. The thing is I have a drawing representation of where the slot is and a cursor that scrolls up and down when the index changes in number. I also approached the direct one which I placed one condition. It works fine, but whenever I go back (for example, I am at slot_index = 3 and I go back to 2), it doesn't work and the cursor just stays there. This only happens when @slot_index is at 2. Because when I scroll back up when I'm at @slot_index = 1, the cursor oscillates back at y = 180, but when I'm at @slot_index = 2 and want to go back at 1, this problem ensues.

@Sixth - I want to use your way. How do I exactly set it up if I want them to scroll properly (scroll vertically). The reason why I set them up at particular y dimension is because the cursor will indicate where I am or what part of the slot I am in.

Slots:

  • 180 - Right Hand
  • 200 - Left Hand
  • 226 - Armor
and so on.
My example assumes that you are working with a selectable window, where the index and the item_rect is automatically adjusted by default.


If your code does not work with a window, than you first must define the y value for each index. If you work with hard-coded values, it can be as simple as adding the Y values into an array, than getting the Y value out of that array is pretty simple ( y = array[@slot_window.index] ).


When you got the Y values set up, you can use the above example code, just replace the way I use to get the Y value with your way and of course the variable names to your own ones. Put both methods into the update method of the scene and it should work.


One big note:


The Y values must be divisible by your scroll speed. If your scroll speed is 2, all Y values must be divisible by 2, or else your cursor will scroll up/down to infinity if it passes the destination check. You can combat this behavior by replacing the '@pic.y == @dest' by '@pic.y >= @dest' or '@pic.y <= @dest' depending on the value of the @dir, but this will not be as precise as the equality check, the cursor can get a few pixels up or down from the destination point.
I have a ruby newbie question involving the fundamental "Don't edit the main engine" rule. I've got a remdial enough understanding to tweak the main engine with extra variables, functions and accessors and stuff, but what is the trick to making all these changes happen from external classes and methods in the allocated space where you are supposed to add the code?

EDIT: Nevermind this problem. I have trouble searching for ruby concepts, because I use javascript terms: how can I word things like.apply(this, arguments);?, and also Google doesn't always give me the best answers with RGSS (maybe because it's not as wide-spread as web scripts),

but I came across a tutorial vid on this very forum that shows two different ways of doing what I was trying to do. Tut-16 on http://forums.rpgmakerweb.com/index.php?/topic/19863-rgss3-scripting-tutorial-videos/
Hi! How much Can I modify Rpgmaker using scripts? Can I make it look almost completely different using tons of scripts? 

Don't worry about the difficulties.
Hi! How much Can I modify Rpgmaker using scripts? Can I make it look almost completely different using tons of scripts? 


Don't worry about the difficulties.
Check the master script list for what has been done before.
There are scripts that turn Ace into an action-RPG, into a platformer jump'n run, into a sidescrolling arcade-fight (as minigame) and more.


Theoretically, everything can be done. Only some things would require so much work that no one has succeeded until now (full online functions for example are still not available, but basic access for highscores etc has been scripted).
Wow, so I can really change my game in a very different game rather than a classic Rpg 😀 And... of course can I sell my game with all of those scripts ( if I legally own and buy everything, scripts, Rpgmaker and resources) without having legal issues with Enterbrain? 
I'm a bit confused about .min and .max (specifically in regards to the damage formula box, if that matters).

I'm testing with two level 1 characters with defense stats of 4 and 16, against a demon that's level 99 (thanks to Yanfly's enemy levels) with an attack of 255.

When I write the damage formula like so:

(a.atk*a.level/2.0)*((512.0-b.def)/256.0)

it returns damage in the 20000's.

But I want to cap it to 9999.

So I tried this:

[(a.atk*a.level/2.0)*((512.0-b.def)/256.0),9999].min

and this:

c=(a.atk*a.level/2.0)*((512.0-b.def)/256.0);d=[c,9999].min

and they both consistently return values between 9200 and 9700. I don't even know where those numbers could come from.

Any thoughts?
It is pretty easy to get the reason.


The damage formula gets calculated before applying the physical/magical damage resistances (or REC stat, in case of recovery).


To top that off, the critical damage multiplier comes after the damage formula, as well as the variance calculation.


The last two can be turned off for the skills, but the resistances will be counted regardless. If you set these resistances to 0 % for every database entry (or just remove them entirely from every database entry), than you will get a pure damage formula calculation without anything else which may alter the final damage.


So, without modifying the damage calculations directly in the scripts, you won't be able to really cap the damage at 9999.


I suggest you take a look at the 'make_damage_value' method in 'Game_Battler', to see exactly how damage is calculated.
That makes sense, thank you for the explanation. I see how it works now.

I also found Shadowmaster9000's damage cap script, which works great, so I'll be using that.
Alchiista93, no, Enterbrain does not require any royalties or anything. You can sell your game, as long as you have permission to use all the resources in it. That's not really a question for this thread (or this part of the forum) though, so if you want any more information on that, I suggest you take up the discussion in the Commercial Discussion forum.
I have a question about Window_ItemList. So, I am adding new commands besides Items, Armors, Weapons and Key Items. I want to add 4 more things, but the thing is since, how will I ensure that when I select the new command, can I assign an item to be the only ones shown in the item window? I can do it if its in a different scene but only one category. Could anyone explain this?

I don't want it to be as complicated as Item Menu done by Yanfly, so the simplest, the best.

Thanks.
Take a look at the 'include?(item)' method in Window_ItemList.


You can add your own condition checks there. You have access to the item and to the currently selected category in the method, so you have plenty of ways to make new conditions.


Actually, Yanfly made that part pretty simple to understand. Assign a custom category for an item with a note-tag, and the category of the item will become a custom one. Than the check in the item list is almost the same, just added a new check to the method mentioned above, which only triggers if the item got a custom category.


The visuals can be hard-coded easily (the buttons for the new categories), but the check must be a dynamic one, and the one Yanfly made is the easiest to do, in my opinion.
I understand, however my main gripe is that they are categories for each types of sets. What I am trying to achieve is to make something like:

Items

Weapons

Armors

Key Items

Valuables

Treasures

and they will be displayed in the same item window. So basically more item categories displayed in one item window. I tried doing this:

#-------------------------------------------------------------------------- # * Create Item List #-------------------------------------------------------------------------- def make_item_list @data = $game_party.all_items.select {|item| include?(item) && !(item.note =~ /<valuables>/i) } @data.push(nil) if include?(nil) endand sure, it does show only the items tagged with valuables on that item window, however, it would be nice to be able to do this with unlimited tags.
This is the easiest method:

alias inclusion_custom6642 include? def include?(item) if item.custom_cat.nil? inclusion_custom6642(item) else return item.custom_cat.include?(@category) end endThis assumes that you made a new instance variable in RPG::BaseItem named @custom_cat which is an array of category identifiers.That can be easily done with note-tags.

You also need to make sure that you get the correct format for both the new @category types in the category window and in the new @custom_cat array for the items.

Since the @category variable used by the item list is the current_symbol of the category window, the custom category array of the items must contain symbols instead of plain strings, since a command window's current_symbol will always be a symbol. Converting the data from the note-tag to symbols should be easy enough thou.

When you want something dynamic, you can't work with a static note-tag (like the one you shown in the example), so you must create a proper dynamic note-tag to spare yourself the multitude of checks which would be needed in the 'include?' method otherwise.
Wait, let me get this correctly, you mean I should make a new method from base item with the array of categories?

class RPG::BaseItem alias base_item_alias_initialize initialize attr_accessor :custom_category def initialize base_item_alias_initialize @custom_category = [/<accessories>/i] end endOr did you mean @custom_category is equal to [:accessories] ?
You are still using static note-tags.

Try this method:

def custom_cat ary = [] if @note =~ /<category: (.*(?:\s*,\s*.*)*)>/i $1.split(/,\s*/).each {|info| ary << info.to_sym} end return ary endPut it in RPG::BaseItem.Then note-tag your items with the name of the custom category. You can use multiple category identifiers in the note-tag if you want.

Examples:

<category: gem>

<category: quest, map>

You can call the above new method on any item.

So, for example, using the second note-tag from the above examples on the 3rd item from the database, $data_items[3].custom_cat will return an array of category symbols, in this case the elements in the array will be :quest and :map.

This is a dynamic note-tag. You must learn them sooner or later, they make scripting a tad bit less bothersome. I hate regex too, but I made a list of commonly used note-tag formulas and methods, and I just copy/paste them from my list when I need them.

Anyway, next step is adding the new buttons for the custom categories. You can hard-code them if you want, the only thing you need to do is add a custom symbol for them, so the comparison can be done without issues.

Still using the above example, you make a button for Quest items with the symbol :quest, and another button for Map with the symbol :map in Window_ItemCategory.

Now head to Window_ItemList, paste the updated 'include?' method from my previous post. Make sure to replace the nil check with 'item.custom_cat != []', because the note-tag I use will return an empty array if there are no custom category note-tags on the item.

Save and test it, it should work. Following the example, you should see the item with the note-tag showing up on the Quest and Map item list only.

You can make unlimited categories this way simply by adding the new category buttons, and using the new note-tag.
I was able to solve the problem by making an @itype_id = x where this is done via the module RPG, class Item. What I did was to check whether the item is on that same category or that number. My solution is rather simpler, but your way is more stable, thanks.

I copied the key_item? function which checks if it is a key item and made my own modification. Turns out it works, but kinda the forced way. I'll try this solution too.
What's the method for calling a troops id? A script uses this:

$game_troop.troop.troop_id

But that only returns an error.

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