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

Bloodmorphed

Dungeon Fanatic
Veteran
Joined
Sep 17, 2012
Messages
1,466
Reaction score
144
First Language
English
Primarily Uses
Okay wow I'm stoooopid for not trying this a long time ago, but apparently all I had to do was this:

#===============================================================================class Window_Base < Window#===============================================================================#-------------------------------------------------------------------------------# alias draw_actor_simple_status#-------------------------------------------------------------------------------alias :bloodysimplestatus :draw_actor_simple_statusalias :bloodyiniti :initialize   def initialize(*args)    bloodyiniti(*args)    @bloodyscale = BloodPLSS::Scale_Settings    @bloodyx1 = @bloodyscale[:posi_level1][:x]    @bloodyy1 = @bloodyscale[:posi_level1][:y]    @bloodyx2 = @bloodyscale[:posi_power1][:x]    @bloodyy2 = @bloodyscale[:posi_power1][:y]    @bloodyx3 = @bloodyscale[:posi_level2][:x]    @bloodyy3 = @bloodyscale[:posi_level2][:y]    @bloodyx4 = @bloodyscale[:posi_power2][:x]    @bloodyy4 = @bloodyscale[:posi_power2][:y]  endAlso my problem was only in a specific part of the code, and I knew where I just didn't know why. I fixed it, but I still don't know why my way didn't weird either. but oooohhhhh well. lol

Now off (after some long earned sleep) to figure out how to make it by class zzzzz.
 
Last edited by a moderator:

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
You might want to start a new topic for this, as this is about a custom script now.

Anyway, I noticed something, which is not relevant to your current error, I guess.

At one place, you are trying to draw an integer. That won't work.

This is the line I am talking about:

draw_text(x, y, 150, line_height, (r / @bloodyscale[:divide]).to_i)That should be:
Code:
draw_text(x, y, 150, line_height, (r / @bloodyscale[:divide]).to_i.to_s)
I rarely use hashes, so I am not sure what is the problem, sorry.And a little tip:

Leave print/p commands where you are not sure what do you need to use and what do you need to convert.

That way you can see what kind of data gets to the specified method and in what form in the console.

This is how I manage to fix most of my problems within seconds, debug number one on my list. :)

You can put these commands everywhere you want in a definition, literally.
For the record, passing an integer to draw_text will work, since that method tries to convert to string anything passed as the text argument. :)

(So don't use .to_s when passing arguments to draw_text)
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
Ohh, and it really works like that too. o.o


I always thought that it can draw strings only, lol.


Thanks, now I will need to remove a lot of .to_s! :D
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
as long as the type can be converting to string they would work... Unless you're drawing something like

draw_text(1 + "x") #simplified for illustration purposesNow this won't work as far as my experience is concerned since you're trying to add a string to an integerBasically, it will only try to convert the end result, not the intermediates.
 
Last edited by a moderator:

Bloodmorphed

Dungeon Fanatic
Veteran
Joined
Sep 17, 2012
Messages
1,466
Reaction score
144
First Language
English
Primarily Uses
Breaking down this "def" just to be 100% on what it is doing

def by_three?(n)    return true if n % 3 == 0 else falseend
return the Boolean(by_three?) as true if n(number) modulo(remainder of n divided by 3) is equal to 0, if not then return false.

I'm pretty sure this is how it is, but I want to make 100% sure, as code academy doesn't explain every little thing like that lol.
 

Venka

Veteran
Veteran
Joined
Jun 20, 2012
Messages
945
Reaction score
365
First Language
English
Primarily Uses
That should work. You can drop the "else false" part though as it's not needed. It'll only return true if the equation is true. You could also do

def by_three?(n) n % 3 == 0endfor the same effect. If the equation is true, it'll return true or false if it isn't
 

Bloodmorphed

Dungeon Fanatic
Veteran
Joined
Sep 17, 2012
Messages
1,466
Reaction score
144
First Language
English
Primarily Uses
Interesting, well it had me doing the return stuff so it made me use that. There are so many ways to do one thing it is quite cool. Lol
 

Venka

Veteran
Veteran
Joined
Jun 20, 2012
Messages
945
Reaction score
365
First Language
English
Primarily Uses
yeah, that's one of the things I like about programming :)

Just to let you know (because it's handy to know for certain occasions).. return will exit out of the current method.

So say you're running a long method and you know you don't need to run all of the code if one of the variables isn't going to check out.

Like this from the Game_BattlerBase

#-------------------------------------------------------------------------- # * Determine if Equippable #-------------------------------------------------------------------------- def equippable?(item) return false unless item.is_a?(RPG::EquipItem) return false if equip_type_sealed?(item.etype_id) return equip_wtype_ok?(item.wtype_id) if item.is_a?(RPG::Weapon) return equip_atype_ok?(item.atype_id) if item.is_a?(RPG::Armor) return false endthe first line will exit out of the method if the item it's checking isn't and equipable item. Since it can't be equipped.. there's no reason to do the other checks.

it will return a value of "false" so which ever method called this one will know the items can't be equipped.

Also it's used like this from the Game_BaseItem script

#-------------------------------------------------------------------------- # * Get Item Object #-------------------------------------------------------------------------- def object return $data_skills[@item_id] if is_skill? return $data_items[@item_id] if is_item? return $data_weapons[@item_id] if is_weapon? return $data_armors[@item_id] if is_armor? return nil endThis one is checking what type of item an object is. So it checks first if it's a skill, if it is, then it will return the skill item. It then checks if it's a item, weapon, armor and if it's no of those, then it will return a nil value.

Hope I'm not muddying the waters for you.
 

Bloodmorphed

Dungeon Fanatic
Veteran
Joined
Sep 17, 2012
Messages
1,466
Reaction score
144
First Language
English
Primarily Uses
Yeah I understand that a pretty good amount actually. I think it's all starting to click for me lol.

But holy moley just adding a sub hash and another uhm idk what to call it, but my oh my how did it change my script from making it globally all actors to specifically editing them individually. I think I love hashes lol.
 

Mihel

Veteran
Veteran
Joined
Mar 13, 2012
Messages
382
Reaction score
42
Primarily Uses
How do I extract n unique random elements from 1..n array?
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
How do I extract n unique random elements from 1..n array?
Code:
array.sample(array.size)# If the array has duplicated elements:array = [1, 2, 2, 2, 3, 4, 5, 10]uniq = array.uniquniq.sample(uniq.size)
 

Mihel

Veteran
Veteran
Joined
Mar 13, 2012
Messages
382
Reaction score
42
Primarily Uses
array.sample(array.size)
Doesn't this sample all of the array elements?

Perhaps I asked the wrong question... I meant to say, if I have [1, 2, 3, 4, 5, 6] array with no duplicates, how do I extract a range of at minimum one random element, and at maximum a number of unique random elements equal to the size of the array?

The result should be something like [3] / [5, 2, 4] / [6, 4, 3, 5, 2, 1]
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
array.sample(array.size)
Doesn't this sample all of the array elements?

Perhaps I asked the wrong question... I meant to say, if I have [1, 2, 3, 4, 5, 6] array with no duplicates, how do I extract a range of at minimum one random element, and at maximum a number of unique random elements equal to the size of the array?

The result should be something like [3] / [5, 2, 4] / [6, 4, 3, 5, 2, 1]
Code:
array = [1, 2, 3, 4, 5, 6]p array.samplep array.sample(3)p array.sample(array.size)
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
In addition to what Source has you can do this:

array = [1, 2, 3, 4, 5, 6]p array.sample(rand(array.size))This will call random id's from the array has them sorted randomly and doesn't matter what size the array is (as it calls rand on the size of the array). *note that it can also get an empty array sometimes.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
How do I extract n unique random elements from 1..n array?
 
array.sample(array.size) Doesn't this sample all of the array elements?
lol, yes, because you said your array was n elements long, and you wanted to extract n elements. If you didn't want ALL of them, you should have used different letters ;)

Sarlecc's example could be changed to always provide at least one result by changing it to this:

Code:
p array.sample([1, rand(array.size)].max)
 

Mihel

Veteran
Veteran
Joined
Mar 13, 2012
Messages
382
Reaction score
42
Primarily Uses
lol, yes, because you said your array was n elements long, and you wanted to extract n elements. If you didn't want ALL of them, you should have used different letters ;)
Oh that's why it didn't make sense, I didn't intend the second n to automatically be the same as the first n although it was also a possibility.

Of course I should have used different letters...  :blush:

Thanks guys.
 

GraveBusta

Vengful
Veteran
Joined
Aug 19, 2014
Messages
150
Reaction score
14
First Language
English
I am gona ask this here because I have a feeling no one wants anymore xasabs topics mine was a general discussion last time not a support thread this question however is a support question and since XASABS has appeared alot I figured it would be better for the community as a whole that I ask for help here.


I am using RMXP, need someone to please help me learn XASABS tool creation. I created the weapon using the skill tab like is instructed and I created a map event with an ID and I created a script part in the XAS weapons tab and well my weapon did not register. 

Please help me using skype,teamviewer,google hangout,or

Rewrite the tutorial with more detail then what the site xasabs.wordpress.com gave I may be over thinking this but I feel as if they didn't put hardly any detail for this. Only my personal feelings and I do not intend to insult the site and say the tutorial sucks because 1 guide might not work for me but will definatley work for others.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
Sorry - that is NOT a question that does not deserve its own thread. You already have a thread for this - let's keep it in a single place.
 

GraveBusta

Vengful
Veteran
Joined
Aug 19, 2014
Messages
150
Reaction score
14
First Language
English
I do not but I still accept the answer no,staff misunderstood the thread I was simply talking about it yes while I mentioned in the comment post about the tutorial lacking the rest was all hype and I was still trying to hard to do it myself at the time I had not intention of asking for help yet. Thank you for your time though :0
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
then start another thread in Script Support. The purpose of this thread is for simple questions that have simple answers, and usually external scripts don't fall into that category.
 

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top