Ace -- help with else ifs for making a speed condition?

● ARCHIVED · READ-ONLY
Started by Arsist 9 posts View original ↗
  1. I want to do something like this:

    def speed if (51..74) === item.id #Spell# speed = subject.xstat.magicspeed + rand(5 + subject.xstat.magicspeed / 4) else if (a.. === item.id #Spellskill# speed = ((subject.agi + rand(5 + subject.agi / 4)) + (subject.xstat.magicspeed + rand(5 + subject.xstat.magicspeed / 4)) / 2) else if (c..d) === item.id #Bow# speed = subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4) else if (e..f) === item.id #Spellbow# speed = ((subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4)) + (subject.xstat.magicspeed + rand(5 + subject.xstat.magicspeed / 4)) / 2) else speed = subject.agi + rand(5 + subject.agi / 4) end speed += item.speed if item speed += subject.atk_speed if attack? speed endwhere there are multiple types of speeds. Heavy armor doesn't slow down your spells or projectile use, but it will slow down your attacks and spellskill (ice blade) moves.

    I'm using http://crystalnoel42.wordpress.com/2013/07/05/crystal-engine-extra-stats/ for the xstats.

    The following works for spell speed, however, I don't know how to work multiple conditions to say if the move is this then this and if it's that then that but if it's none of those then it's this.

    def speed if (51..74) === item.id #Spell# speed = subject.xstat.msp + rand(5 + subject.xstat.msp / 4) else speed = subject.agi + rand(5 + subject.agi / 4) end speed += item.speed if item speed += subject.atk_speed if attack? speed += subject.xstat.actadd speed -= 1000 speed *= subject.xstat.actmulti speed *= 0.01 speed endMight someone help?

    I wonder if the condition only works for skills and not items.
  2. Sounds like a job for a case statement.
  3. Do you mean:

    def speed if (51..74) === item.id #Spell# speed = subject.xstat.magicspeed + rand(5 + subject.xstat.magicspeed / 4) elsif (a.. === item.id #Spellskill# speed = ((subject.agi + rand(5 + subject.agi / 4)) + (subject.xstat.magicspeed + rand(5 + subject.xstat.magicspeed / 4)) / 2) elsif (c..d) === item.id #Bow# speed = subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4) elsif (e..f) === item.id #Spellbow# speed = ((subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4)) + (subject.xstat.magicspeed + rand(5 + subject.xstat.magicspeed / 4)) / 2) else speed = subject.agi + rand(5 + subject.agi / 4) end speed += item.speed if item speed += subject.atk_speed if attack? speed endOkay. That works.

    But how would this work for items and not just skills?
  4. Where is the case statement in that?
  5. Haha, spare me. I had to look up what case statements are and I found

    http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/

    I tried

    def speed when '795','796','797' === item.id #Spell# speed = subject.xstat.msp + rand(5 + subject.xstat.msp / 4) when '798','799','800' === item.id #Spellskill# speed = ((subject.agi + rand(5 + subject.agi / 4)) + (subject.xstat.msp + rand(5 + subject.xstat.msp / 4)) / 2) when '801','802','803' === item.id #Bow# speed = subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4) when '804','805','806' === item.id #Spellbow# speed = ((subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4)) + (subject.xstat.msp + rand(5 + subject.xstat.msp / 4)) / 2) else speed = subject.agi + rand(5 + subject.agi / 4) end speed += item.speed if item speed += subject.atk_speed if attack? speed endThat didn't work for me. Which I didn't see === in the regular examples so I got confused as to how I could do it. And I also saw elsif being used there so I thought that too was a case statement

    So now I don't know how to do what's-included-in-the-parenthesis or item speed and not just skill speed.

    I was unsure how to apply this topic http://forums.rpgmakerweb.com/index.php?/topic/27229-quickly-condtion-an-array-eg-game-variables1-01467/#entry261204 to the parenthesis-based skill id.
  6. You're using expressions that I have no idea about. I don't know if it's because they're more advanced than I've ever needed to use, so I haven't learned them, or if you're just guessing and don't really know. But based on the last few posts, I'm guessing that you're just guessing. I'm also not sure it's a good idea to give a variable the same name as your method.

    Try this:

    def speed case item.id when 795,796,797 #Spell# sp = subject.xstat.msp + rand(5 + subject.xstat.msp / 4) when 798,799,800 #Spellskill# sp = ((subject.agi + rand(5 + subject.agi / 4)) + (subject.xstat.msp + rand(5 + subject.xstat.msp / 4)) / 2) when 801,802,803 #Bow# sp = subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4) when 804,805,806 #Spellbow# sp = ((subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4)) + (subject.xstat.msp + rand(5 + subject.xstat.msp / 4)) / 2) default sp = subject.agi + rand(5 + subject.agi / 4) end sp += item.speed if item sp += subject.atk_speed if attack? sp endNow, I'm not sure if subject.xstat.msp is valid (or any of the other similar ones). I suspect it probably isn't, so you should do some investigation and find out what the correct expression is.I'm also not sure if default is correct as the catch-all. It might be else or other. You could do a global search (contro+shift+F) in the scripts for case and just see if you can find one that has a catch-all, and what the correct term is to use.

    In fact, just looking at the end result, why do you do a comparison based on item.id and then later do something with if item as a condition? If item is nil, your method will fail at the very start. What class have you added this code to? If it's an item class, then you KNOW item will not be nil.
  7. It's

    class Game_Actionand I think you use 'else'. 'Default' doesn't work in this instance.

    You get to use xstat.statname when using Crystal's Extra Stats that I linked.

    So I'm assuming you would do

    Code:
      def speed    if action?      case item.id        when 795,796,797 #Spell#          speed = subject.xstat.msp + rand(5 + subject.xstat.msp / 4)        when 798,799,800 #Spellskill#          speed = ((subject.agi + rand(5 + subject.agi / 4)) + (subject.xstat.msp + rand(5 + subject.xstat.msp / 4)) / 2)        when 801,802,803 #Bow#          speed = subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4)        when 804,805,806 #Spellbow#          speed = ((subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4)) + (subject.xstat.msp + rand(5 + subject.xstat.msp / 4)) / 2)        else          speed = subject.agi + rand(5 + subject.agi / 4)      end    if item      case item.id        when x,x,x #throwing#          speed = (formula)        else          speed = (regular formula)      end      speed += item.speed if item      speed += subject.atk_speed if attack?      speed    end
  8. Code:
    def speed  if item.class == RPG::Skill #when skills    case item.id      when 795..797        speed = subject.xstat.msp + rand(5 + subject.xstat.msp / 4)      when 798..800        speed = ((subject.agi + rand(5 + subject.agi / 4)) + (subject.xstat.msp + rand(5 + subject.xstat.msp / 4)) / 2)      when 801..803        speed = subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4)      when 804..806        speed = ((subject.xstat.bowspeed + rand(5 + subject.xstat.bowspeed / 4)) + (subject.xstat.msp + rand(5 + subject.xstat.msp / 4)) / 2)      else        speed = subject.agi + rand(5 + subject.agi / 4)    end  else    case item.id #when items      when x..y        speed = z      else      speed = subject.agi + rand(5 + subject.agi / 4)    end  end  speed += item.speed if item  speed += subject.atk_speed if attack?  speedend
  9. Yes, just looked it up. You're right - it's else.