0 reviews
  • Add Review
  • Subscribe
  • Nominate
  • Submit Media
  • RSS

More on Learning RGSS2

  • Versalia
  • 04/24/2011 07:47 PM
  • 618 views
One of the topics I wanted to make sure I hit on was how I'd been progressing in learning the VX editor and its scripting language, RGSS2. My first post was extremely basic and general in that regard, and showed off some similarly basic blocks of code; I'll take at one of those as an example here, Aisling's Fencer role, and show you how it has progressed.

Let's look at Aisling's Fencer ability. This should earn her some sync whenever she does a weapon attack, or a physical attack skill, and should earn more than usual if she gets a critical hit. Here's what the old version looked like:

(I'll dissect these lines for you in a moment.)

As you can see, she gains 4 Sync ("rage") whenever she does an 'attack' or a skill tagged 'physical.' However - what happens if the enemy is immune to physical damage?! She might not actually DEAL any damage, and would not deserve any Sync for that action! Additionally, she might have activated Llyn Llydaw, which turns her physical attacks into Water attacks ... that should still give her Sync, because it's a physical attack, but if the enemy absorbs Water ... well, it's the same problem. So first, I used the magical Ctrl+Shift+F key. This searches for every instance of the given text in every possible script. I looked for "damage" and I found some lines using something called hp_damage. So I tried sandwiching the fencer code with this: if hp_damage > 0. That way, it would not trigger if she did 0 or less damage. However, this threw me some kind of error; "unknown method > for nil(nilclass)" or somesuch. On closer inspection, I realized that for whatever reason, you must attach hp_damage to a constant to be able to use comparisons like ==, >, <=, etc.

A constant is a lot like a game's variables. Switches contain data (either ON or OFF); Variables contain data (Any number); Constants also contain data (any word or number). I can make up the name of a constant on the fly. If I suddenly want to say that something called "Shamalamadingdong" exists, and that is has a value of "Purple People Eater", I can do that. It's as easy as typing Shamalamadingdong = "purple people eater" into the script. I want to keep mine related to HP damage, though, so I used

hpdmg = hp_damage

If this were a game variable, you can visualize it this way:


I set my "hpdmg" constant to be the same value as hp_damage. Now I swap out hp_damage for hpdmg in the original formula. No error! Success! If Hpdmg is > 0, then Fencer works properly. Score!! VICTORY DANCE!! But wait! I still have to deal with critical hits. Back to our old friend CTRL+SHIFT+F and the word "critical." Gosh, that gives me a ton of results! Well, some browsing shows me script using target.critical. It LOOKS like this means "if the target has been critically hit." (Digging into other script confirms this; it looks like the 'critical' flag gets attached to an enemy when they get critically hit. You'd think it might be "user.critical" since you're the one doing the attacking, but since the thing whose HP is actually being -changed- is the victim of your attack, all the calculations revolve around them.) So let's toss in a check for target.critical. I do some database trickery to make sure Aisling has 100% critical rate, and... success! She gains twice as much sync for a critical hit!

All done, right? Wrong! I noticed that when applying a buff that raises how much sync you get, it doesn't actually do anything. Hmmmmm. Looking at gain_rage, I see this line: value = rage_modifiers(value). Hmmm! I see what's going on here - I specified the value already, as a flat 4. See that in gain_rage(4) in the original screenshot? Instead, let's copy what gain_rage does with the modifiers.



On the last line, we create a pop-up that shows how much sync Aisling gained. Sort of like a popup showing the damage when you attack enemies. "RAGEGAIN" is just the name I gave that popup template; I have specified that RAGEGAIN-style popups are a specific color, etc. Much like HP damage is a different color than HP Healing; I could use "HPGAIN" style popups, but I want to make sure you know it is Sync gain. (Instances of sync are once again, by default, modifications of the 'rage' system.)

Well, it's not any kind of in-depth tutorial, but I hope this is helpful or interesting to someone out there! It shows how an extremely basic block of scripting evolved into a more mature one over a couple of days of experimenting and practice.

Posts

Pages: 1
"unknown method > for nil(nilclass)" means that the variable hp_damage had not been declared. By default, undeclared variables are registered as "nil" when used before declaration; however, nil cannot be used for comparison operations, hence the error.

case @actual_code_written

when "if hp_damage > 0"
Change hp_damage to "target.hp_damage". Don't forget to break from the method when there is no target! ("target.nil?" / "target == nil")

when "if target.hp_damage > 0"
Are you sure the error wasn't "unknown method hp_damage for nil(nilclass)"? That would mean that target was nil, and you can't reference anything from nilclass. Check that the target is correct, then use target.hp_damage. It could be, also, that hp_damage itself is nil, but then transferring nil to hpdmg wouldn't make any sense... what a peculiar bug.

end
Versalia
must be all that rtp in your diet
1405
author=AeroGP
"unknown method > for nil(nilclass)" means that the variable hp_damage had not been declared. By default, undeclared variables are registered as "nil" when used before declaration; however, nil cannot be used for comparison operations, hence the error.

case @actual_code_written

when "if hp_damage > 0"
Change hp_damage to "target.hp_damage". Don't forget to break from the method when there is no target! ("target.nil?" / "target == nil")

when "if target.hp_damage > 0"
Are you sure the error wasn't "unknown method hp_damage for nil(nilclass)"? That would mean that target was nil, and you can't reference anything from nilclass. Check that the target is correct, then use target.hp_damage. It could be, also, that hp_damage itself is nil, but then transferring nil to hpdmg wouldn't make any sense... what a peculiar bug.

end

Thank you for knowing what you're talking about. I'm self-teaching so I dunno how to express these things :B You're right, I have no idea why I wasn't using target.hp_damage (which I am aware is correct) although I'd also like to point out I lied and rage_modifiers doesn't like to be called in this manner (but I wrote my own). I wrote the bug message from memory, but it was definitely a nilclass error.
Pages: 1