Jump to content
DorFenn

[VXA] Move the skills to the item menu

Recommended Posts

Hello everyone! You see, I am creating a menu for the SaS IV (Or Saphire Action System) battle system, and the problem is that when creating the item window, these are not shown but the skill is. It is very problematic since I have tried to add the skills as an item in the categories, but I cannot get the skill to show next to the items in any way.

I put the "item.is_a?(RPG:Skill) on the category
 

Ruby:
  def include?(item)
    case @category
    when :item
      item.is_a?(RPG::Item) && !item.key_item? or item.is_a?(RPG::Weapon) or item.is_a?(RPG::Skill)
    when :key_item
      item.is_a?(RPG::Item) && item.key_item?
    else
      false
    end
  end

This is the list created, the original is after the "Else". I have the problem that it shows me only the skills.
 

Ruby:
  def make_item_list
    if skill = $game_party.members.any? { |actor| actor.skills.include?($data_skills[9]) }
    @data = $game_party.all_items.select {|item| include?(item) }
    @data = $data_skills.select {|skill| usable?(skill) }
    @data.push(nil) if include?(nil)
  else
    @data = $game_party.all_items.select {|item| include?(item) }
    @data.push(nil) if include?(nil)   
  end
end

I would greatly appreciate if you could teach me a way to display Skills and Items within the same category.

I've only made these changes to the menu, so I can't find anything else to clarify.

Share this post


Link to post
Share on other sites
Posted (edited)

Cause you are using '@data =' twice in make_item_list, so the list of skills is overwriting the list of items.

 

Try adding a '+' before the '=' for the second one, or to put it another way,

 

change:

@data = $data_skills.select {|skill| usable?(skill) }

into:

@data += $data_skills.select {|skill| usable?(skill) }

That will tell ruby to append the array rather then overwrite it.

Edited by Kayzee

Share this post


Link to post
Share on other sites

Hey Kayzee! Thanks for the help, I have tried it in many ways but it gives me an error as soon as I put the "+" behind the equal.

 

I honestly don't know what could be generating this.

 

Here is the error:

Spoiler

1668675595_Sinttulo-1.png.f3ecae6cfd10d07cf2c4668477d0e0bf.png

 

 

I know that you said that the "+" must go after the "=", but the error it shows me is the same.

 

Greeting and have a nice day.

Share this post


Link to post
Share on other sites
Posted (edited)
3 hours ago, DorFenn said:

I know that you said that the "+" must go after the "=", but the error it shows me is the same.

The + goes before the =

like Kayzee showed you in the code block.

If that gives an error then there is a coding block where that section does not recognize using math operators in a full capacity.

the other option that may work is

@data << $data_skills.select {|skill| usable?(skill) }

The << is a push operator. It is used to add on data

Edited by roninator2
grammer

Share this post


Link to post
Share on other sites

Thank you very much Rorinator! I have managed to show it, now I only have to lay some basic things and it be like new.

 

In case someone has a similar problem attached as it should be the code.

 

  def make_item_list
    if skill = $game_party.members.any? { |actor| actor.skills.include?($data_skills[9]) }
    @data = $game_party.all_items.select {|item| include?(item) }
    @data << $data_skills[9]
    @data.push(nil) if include?(nil)
  else
    @data = $game_party.all_items.select {|item| include?(item) }
    @data.push(nil) if include?(nil)    
  end
end

Greeting and have a nice day.

Share this post


Link to post
Share on other sites
6 hours ago, roninator2 said:

...

If that gives an error then there is a coding block where that section does not recognize using math operators in a full capacity. 

the other option that may work is


@data << $data_skills.select {|skill| usable?(skill) }

The << is a push operator. It is used to add on data

 

Keep in mind that += and << do very different things. Pretty sure that << works identically to the .push method, adding something as a new member on to the array. On the the other hand += is a way of combining two arrays into one. In this case, '$data_skills.select {|skill| usable?(skill) }' is an array containing all usable skills. Using << here would add one new member to the @data array containing the usable skills array, which is not what we would want is it? Using += here would add each member of the usable skills array to the end of the @data array, which is what we would actually want to do.

 

Side note: By a 'section that does not use math operators in a full capacity' I can only assume you are talking about the traditional difference between 'statements' and 'expressions' in many programing languages. In some languages operations like += might be defined as 'statements' and not allowed to be used where the language expects an 'expression'. Probably mostly in languages that use '=' to both set if used as a statement (such as 'x = 5') and compare things if used as an expression (such as 'if x = 5') rather then use '=' to set and '==' to compare. In Ruby however the difference between 'statements' and 'expressions' is virtually (but I don't think entirely) nonexistent.

 

Otherwise, math operators are defined purely by the object(s) they operate on. The biggest reason something like 'x += y' might give an error is that ether the + operator is not defined for the class of x, or that the + operator for the class of x is unable to handle an object of the class of y. Happens most often in my experience because x and/or y were never actually set and default to nil.

 

Then again...

 

4 hours ago, DorFenn said:

Thank you very much Rorinator! I have managed to show it, now I only have to lay some basic things and it be like new.

 

In case someone has a similar problem attached as it should be the code.

 


  def make_item_list
    if skill = $game_party.members.any? { |actor| actor.skills.include?($data_skills[9]) }
    @data = $game_party.all_items.select {|item| include?(item) }
    @data << $data_skills[9]
    @data.push(nil) if include?(nil)
  else
    @data = $game_party.all_items.select {|item| include?(item) }
    @data.push(nil) if include?(nil)    
  end
end

Greeting and have a nice day.

 

I am kind of confused because I thought you wanted a bunch of skills to show up in the item menu, not just one?

 

Share this post


Link to post
Share on other sites
5 hours ago, Kayzee said:

talking about the traditional difference between 'statements' and 'expressions' in many programming languages

I honestly have no idea. I do know from experience that

5 hours ago, Kayzee said:

biggest reason something like 'x += y' might give an error is that ether the + operator is not defined for the class of x, or that the + operator for the class of x is unable to handle an object of the class of y

That;s why I suggested the << operator as an alternate.

I didn't think there was an issue with the << operator though.

 

I had used in my project something like this

object = data1

totaldata = totaldata + object

and that works. but 

totaldata += object ; does not

I don't understand why. If + works by itself then math operators are defined but += is not? They all fall under their parent classes, or at least they should.

 

Well I'm still learning ruby.. Lesson 93/174 on udemy.

 

And yes it is weird to only add on 1 skill.

Share this post


Link to post
Share on other sites

Yes, I know it is rare that I have asked based on all the skills, but I realized that it is convenient for me to do it conditionally. In this way I can control what skills are seen and what others are not.

 

Forgive the confusion.

Share this post


Link to post
Share on other sites
Posted (edited)
8 hours ago, roninator2 said:

That;s why I suggested the << operator as an alternate.

I didn't think there was an issue with the << operator though. 

 

One alternative to 'x += y' for arrays would I think be 'x.push(*y)' where * in this case is the splat operator. Not sure if 'x << *y' would work though, because although .push accepts multiple arguments, I am not sure if << does.

 

8 hours ago, roninator2 said:

I had used in my project something like this

object = data1

totaldata = totaldata + object

and that works. but 

totaldata += object ; does not

I don't understand why. If + works by itself then math operators are defined but += is not? They all fall under their parent classes, or at least they should.

 

Yeah that's weird... as far as I know += should be defined if + is defined... Though it could be that for totaldata's class '+' is not defined, but it is for object's class and Ruby will use object's '+' when it encounters that situation because for numbers x + y and y + x are the same thing. This isn't always true for other types of objects, but I could imagine this being assumed.

 

If so, this is what I might expect to happen if 'totaldata' is nil (or undefined) and 'object' is a string. Saying something like ' nil + "string" ' might actually work fine then because Ruby would reinterpret it as ' "string" + nil ' which would try and convert nil to a string by calling nil.to_s which I believe always returns the empty string (aka ""). Therefore 'totaldata = totaldata + object' would work, even though it really shouldn't.

 

However 'totaldata += object' would not. Because + is not defined for totaldata, += would not be defined either and in this case Ruby would not assume that x += y is the same as y += x because they obviously wouldn't be the same even for numbers.

 

Usually in that case you would want to set totaldata to "" before you start using it. That way you are absolutely sure it's a string.

 

3 hours ago, DorFenn said:

Yes, I know it is rare that I have asked based on all the skills, but I realized that it is convenient for me to do it conditionally. In this way I can control what skills are seen and what others are not.

 

Forgive the confusion.

 

Good luck then! *sprinkles fairy dust on you*

Edited by Kayzee

Share this post


Link to post
Share on other sites
1 hour ago, Kayzee said:

Yeah that's weird... as far as I know += should be defined if + is defined... Though it could be that for totaldata's class '+' is not defined, but it is for object's class and Ruby will use object's '+' when it encounters that situation because for numbers x + y and y + x are the same thing. This isn't always true for other types of objects, but I could imagine this being assumed.

 

If so, this is what I might expect to happen if 'totaldata' is nil (or undefined) and 'object' is a string. Saying something like ' nil + "string" ' might actually work fine then because Ruby would reinterpret it as ' "string" + nil ' which would try and convert nil to a string by calling nil.to_s which I believe always returns the empty string (aka ""). Therefore 'totaldata = totaldata + object' would work, even though it really shouldn't.

 

However 'totaldata += object' would not. Because + is not defined for totaldata, += would not be defined either and in this case Ruby would not assume that x += y is the same as y += x because they obviously wouldn't be the same even for numbers.

 

Ok. So it may have been a clash with the object.class features/calls/sets? can't remember the term.

interesting. Thanks

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks for the comments (? I'll save those explanations for the future. Now I have another problem for this... The skill is displayed in the common items menu and the special items menu.

Does anyone know the why of this?

 

Now I attach the script that is almost ready (Do not try it because images are missing and all that.)

 

I'm sorry if it's in Spanish. It is my first language and the script guided it that way.

 

Greetings and good night (?

Edited by DorFenn

Share this post


Link to post
Share on other sites

Maybe add in if condition

  def make_item_list
    if skill = $game_party.members.any? { |actor| actor.skills.include?($data_skills[9]) }
	  @data = $game_party.all_items.select {|item| include?(item) }
	  @data << $data_skills[9] if @category == :item
	  @data.push(nil) if include?(nil)
	else
	  @data = $game_party.all_items.select {|item| include?(item) }
	  @data.push(nil) if include?(nil)    
	end
  end

 

Share this post


Link to post
Share on other sites

Thank you thank you very much!

 

I honestly didn't think it could be solved, even though I looked and asked for help I hadn't seen any topic related to what I was looking for.

 

You and Kayzee are great!

Share this post


Link to post
Share on other sites

About the only improvement I would make is to change it so that it scans for one skilltype by ID.
Like, have all healing spells/skills be one skilltype ID (this is zero-based but ID 0 is 'None' and is not typically used by the player).

Share this post


Link to post
Share on other sites

 

I did think about it. But seeing that I only use three skills doesn't make much sense to me at least.

So I make just one general modification that conditionally adds those three.

Although maybe someone else is the same as me, unless you want to add all the skills.

(Although I have not seen anyone who wants to mix skills within the menu of items xd)

Share this post


Link to post
Share on other sites
On 5/29/2020 at 3:41 PM, roninator2 said:

Ok. So it may have been a clash with the object.class features/calls/sets? can't remember the term.

interesting. Thanks

 

Methods maybe? Operators in Ruby are really just fancy methods. For example this would be how you actually define '+':

 

class SomeClass

  def +(value)
    # do something here
  end

end

Really in Ruby 'x + y' kinda translates to 'x.+(y)'

 

1 hour ago, PhoenixSoul said:

About the only improvement I would make is to change it so that it scans for one skilltype by ID.
Like, have all healing spells/skills be one skilltype ID (this is zero-based but ID 0 is 'None' and is not typically used by the player).

 

Personally I would have probobly used a note tag of some kind.

 

Though really items and skills are basically the same thing. In most cases you could probably just use reusable items instead of skills, but I don't know if that is practical in this case.

Share this post


Link to post
Share on other sites
50 minutes ago, Kayzee said:

Personally I would have probobly used a note tag of some kind.


That works too.

 

2 hours ago, DorFenn said:

 

I did think about it. But seeing that I only use three skills doesn't make much sense to me at least.


Ah, I see. Yeah; no purpose in scanning a lot of skills that aren't going to be used, or that won't be visible anyway.
(I thought the `$data_skills[9]` was a placeholder-whoops)

Share this post


Link to post
Share on other sites
15 hours ago, Kayzee said:

Personally I would have probobly used a note tag of some kind.

Regarding the Note Tag I was going to try it, but when I read a tutorial and it was too much to scan, I decided to use the conditionals after all. From what I do, three skills are nothing compared to those people who use a lot of them.

14 hours ago, PhoenixSoul said:

Ah, I see. Yeah; no purpose in scanning a lot of skills that aren't going to be used, or that won't be visible anyway.
(I thought the `$data_skills[9]` was a placeholder-whoops)

 

You can see it as a placeholder xd Although it helps me too much to know which line I should edit in the future. Luckily now I can progress on my own, thanks to everyone again!

Share this post


Link to post
Share on other sites
8 hours ago, DorFenn said:

Regarding the Note Tag I was going to try it, but when I read a tutorial and it was too much to scan, I decided to use the conditionals after all. From what I do, three skills are nothing compared to those people who use a lot of them.

 

Yeah note tags can be a pain in the butt to deal with sometimes, especially since every script basically needs it's own way to load/parse them. Personally though when I write scripts I don't even bother making each script load/parse it's own note tags and use this script to load/parse stuff for all my scripts instead. It makes things a million times simpler for me as someone who makes a lot of my own scripts. If you only are using three skills though? Yeah, just use conditionals I say.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×