Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Yet another newbie query, Skills adding to variables?
Crazy Rob
post Jul 21 2012, 02:18 AM
Post #1


Level 1
Group Icon

Group: Member
Posts: 11
Type: Developer
RM Skill: Skilled




I hope I'm not going over old ground that's been walked to death, but is there a way to make it so that when a skill is used, it adds 1 to a variable?

I could do it with a common event for each one I need to function that way, but that seems wasteful. Any scripts or tips?
Go to the top of the page
 
+Quote Post
   
Tsukihime
post Jul 21 2012, 11:17 AM
Post #2


Level 25
Group Icon

Group: Revolutionary
Posts: 565
Type: None
RM Skill: Undisclosed
Rev Points: 25




Game_Battler#item_apply is when you actually use a skill/item, which gives you the skill/item.

You can extend it to increment a variable by checking if it's a skill and then grabbing the skill ID.


__________________________
My Scripts
Go to the top of the page
 
+Quote Post
   
Crazy Rob
post Jul 21 2012, 10:09 PM
Post #3


Level 1
Group Icon

Group: Member
Posts: 11
Type: Developer
RM Skill: Skilled




Here's what I have for coding.

def attack_apply(attacker)
item_apply(attacker, $data_skills[attacker.attack_skill_id])
return $game_variables[7] + 1 if attack_skill_id = 56
return $game_variables[7] + 2 if attack_skill_id = 57
return $game_variables[7] + 4 if attack_skill_id = 58
return $game_variables[7] + 10 if attack_skill_id = 59
end

I've tried it with and without the return at the beginning. The system doesn't crash, it just doesn't add the values of 1, 2, 4, or 10 to variable 7 when those skills are used.

I'm a newbie coder. What am I doing wrong?
Go to the top of the page
 
+Quote Post
   
Tsukihime
post Jul 22 2012, 10:19 AM
Post #4


Level 25
Group Icon

Group: Revolutionary
Posts: 565
Type: None
RM Skill: Undisclosed
Rev Points: 25




QUOTE
What am I doing wrong?


Well, can you explain what you did and what you were hoping to achieve by writing your code that way?

Figuring out what went wrong is something you should also be thinking about as a coder.
Most coders probably spend more time tossing keyboards across the room than actually typing because things don't work the way they expected.

This post has been edited by Tsukihime: Jul 22 2012, 10:20 AM


__________________________
My Scripts
Go to the top of the page
 
+Quote Post
   
diamondandplatin...
post Jul 22 2012, 10:44 AM
Post #5


Level 5
Group Icon

Group: Member
Posts: 72
Type: Writer
RM Skill: Skilled
Rev Points: 45




QUOTE
CODE
def attack_apply(attacker)
item_apply(attacker, $data_skills[attacker.attack_skill_id])
return $game_variables[7] + 1 if attack_skill_id = 56
return $game_variables[7] + 2 if attack_skill_id = 57
return $game_variables[7] + 4 if attack_skill_id = 58
return $game_variables[7] + 10 if attack_skill_id = 59
end


You need to use the ' += ' operator.

All you're doing there is telling the CPU to do a math equation without giving a result to anything.


CODE
def attack_apply(attacker)
item_apply(attacker, $data_skills[attacker.attack_skill_id])
$game_variables[7] += 1 if attack_skill_id = 56
$game_variables[7] += 2 if attack_skill_id = 57
$game_variables[7] += 4 if attack_skill_id = 58
$game_variables[7] += 10 if attack_skill_id = 59
end


Using += you're telling the computer to add on the the first equation.

EDIT: Also I didn't notice this earlier, but you're also trying to assign a number to your skill ID's


CODE
def attack_apply(attacker)
item_apply(attacker, $data_skills[attacker.attack_skill_id])
$game_variables[7] += 1 if attack_skill_id == 56
$game_variables[7] += 2 if attack_skill_id == 57
$game_variables[7] += 4 if attack_skill_id == 58
$game_variables[7] += 10 if attack_skill_id == 59
end


You need to use ' == ' when checking if something is equal to something.


Using the equals symbol on its own will always assign (or attempt to) something .

if attack_skill_id = 56 # <- This is not good, don't do it when checking it.
if attack_skill_id == 56 # <- That's what you want.

Merging your posts. Please do not double post ~ Ratty524

This post has been edited by Ratty524: Jul 22 2012, 11:47 AM


__________________________
Go to the top of the page
 
+Quote Post
   
Crazy Rob
post Jul 22 2012, 11:57 AM
Post #6


Level 1
Group Icon

Group: Member
Posts: 11
Type: Developer
RM Skill: Skilled




what I was trying to achieve was that whenever a certain set of skills were used, a variable (variable 7 in this case) would be increased.

Use the weakest fire spell, 1 is added, use the strongest, and 10 is added.

Trying the recent method posted by diamondandplatinum isn't working, though. This is in the game_battler section as noted above.
Go to the top of the page
 
+Quote Post
   
Tsukihime
post Jul 22 2012, 07:01 PM
Post #7


Level 25
Group Icon

Group: Revolutionary
Posts: 565
Type: None
RM Skill: Undisclosed
Rev Points: 25




If you do a find-all search for "attack_apply" you might notice that nothing is actually calling that method (lol EB must've thought of doing something but then changed their mind)

Just add your changes to `item_apply`

This post has been edited by Tsukihime: Jul 22 2012, 07:01 PM


__________________________
My Scripts
Go to the top of the page
 
+Quote Post
   
Crazy Rob
post Jul 23 2012, 01:17 PM
Post #8


Level 1
Group Icon

Group: Member
Posts: 11
Type: Developer
RM Skill: Skilled




This is the revised code under the second "item_apply" in the game_battler script...

#--------------------------------------------------------------------------
# * Apply Effect of Skill/Item
#--------------------------------------------------------------------------
def item_apply(user, item)
@result.clear
@result.used = item_test(user, item)
@result.missed = (@result.used && rand >= item_hit(user, item))
@result.evaded = (!@result.missed && rand < item_eva(user, item))
$game_variables[7] += 1 if attack_skill_id == 56
$game_variables[7] += 2 if attack_skill_id == 57
$game_variables[7] += 4 if attack_skill_id == 58
$game_variables[7] += 10 if attack_skill_id == 59
if @result.hit?
unless item.damage.none?
@result.critical = (rand < item_cri(user, item))
make_damage_value(user, item)
execute_damage(user)
end
item.effects.each {|effect| item_effect_apply(user, item, effect) }
item_user_effect(user, item)
end
end

Still nothing. Not even a crash. Am I just stupid?
Go to the top of the page
 
+Quote Post
   
Tsukihime
post Jul 24 2012, 10:54 AM
Post #9


Level 25
Group Icon

Group: Revolutionary
Posts: 565
Type: None
RM Skill: Undisclosed
Rev Points: 25




attack_skill_id is always 1.


__________________________
My Scripts
Go to the top of the page
 
+Quote Post
   
Crazy Rob
post Jul 24 2012, 12:10 PM
Post #10


Level 1
Group Icon

Group: Member
Posts: 11
Type: Developer
RM Skill: Skilled




...are you saying that the way I wrote it the skill id will always be 1, or that no matter how I write the script it will be 1?
Go to the top of the page
 
+Quote Post
   
udivision
post Jul 27 2012, 02:32 PM
Post #11


Level 12
Group Icon

Group: Revolutionary
Posts: 218
Type: Developer
RM Skill: Skilled




replace "attack_skill_id"

with

user.attack_skill_id

or

item.id


__________________________
Go to the top of the page
 
+Quote Post
   
Crazy Rob
post Jul 27 2012, 06:16 PM
Post #12


Level 1
Group Icon

Group: Member
Posts: 11
Type: Developer
RM Skill: Skilled




Halle-effing-lujiah.

Item.id worked. Thank you, udivision.
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th June 2013 - 03:47 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker