changing classes

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
Can someone please tell me how to write out a def to change an actors class?

This what i have right now.

Code:
    def change_classes        selected_actor = $game_system.selected_actor        selected_class = $game_system.selected_class        $game_actor[selected_actor].change_class(selected_class) #I keep getting an error on this line it says it an unrecognized []    end
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I've moved this thread to RGSSx Script Support (I have NO idea why you would have posted this in Classifieds - Offers). Please be sure to post your threads in the correct forum next time. Thank you.


There is no such thing as $game_actor. It is $game_actors.
 
Last edited by a moderator:

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
I figured that out and I actually wanted $game_party instead, but thanks again Shaz and sorry for posting in the wrong place thought I was in learning ruby.
 
Last edited by a moderator:

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
Shaz was right. It was just a spelling error.

Code:
    def change_classes        selected_actor = $game_system.selected_actor        selected_class = $game_system.selected_class       $game_party.members[0].change_class(class_choice, keep_exp = false)  #works fine no problems and since I'm setting it up to only have 1    end                                                                      possible team member it works perfectly.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
What are selected_actor and selected_class and class_choice? You've set the first two but don't use them anywhere, so unless they're methods in your class, they do absolutely nothing, and you're using class_choice but you haven't set it anywhere, so unless it's also a method, it's not going to work. And why do you have $game_system.selected_actor and $game_system.selected_class? Are you actually creating a new menu or something?


In addition, that change_class call is not going to work anyway, because you've passed keep_exp = false as the second parameter. This is ALWAYS going to evaluate to true, because you're assigning a value to a variable. You don't pass in the name of a parameter to a method, and if you pass in an operation it's going to evaluate that and pass in the result (keep_exp = false will always evaluate to true because you have successfully put something into a variable).


So if this actually works for you, all well and good - you've obviously got a lot of other things happening behind the scenes that affect this method that we can't see. But if you're not absolutely certain of what you're doing, I suspect most of this needs to be changed.
 
Last edited by a moderator:

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
 Yes I am creating a menu. This is the actual method from the script.

Now I'm having problems with the switch if someone wants to help with that.

It says it can't convert the string into an integer

Code:
def remove_remaining_members    face_choice = ($game_system.face_choice + 1)    class_choice = $game_system.class_choice        $game_party.members.each_index do |i|      next if i == face_choice      $game_party.remove_actor(i)      $game_party.remove_actor($game_party.members.size) unless face_choice == $game_party.members.size    end          $game_party.members[0].change_class(class_choice, keep_exp = false)    actor_switch = $data_actors[face_choice].note[/<Actor_Switch:\s*(\d*)>/]    # <-------- these lines    $game_switches[actor_switch] = true    # <-------- these lines  end
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
/<Actor_Switch:\s*(\d*)>/ gives you a string. You need to use .to_i to convert it to an integer. I don't know if you can do that on all one line - maybe [(/<Actor_Switch:\s*(\d*)>/).to_i]
 

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
I tried putting the .to_i inside of the note expression and it gave me an error.

There is no error now, but it is not turning the switches true.

I have set up events testing the switches and none of them are activating.

The Database is set up properly.

Code:
  def remove_remaining_members    face_choice = ($game_system.face_choice + 1)    class_choice = $game_system.class_choice        $game_party.members.each_index do |i|      next if i == face_choice      $game_party.remove_actor(i)      $game_party.remove_actor($game_party.members.size) unless face_choice == $game_party.members.size    end          $game_party.members[0].change_class(class_choice, keep_exp = false)    actor_switch = $data_actors[face_choice].note[/<Actor_Switch:\s*(\d*)>/].to_i    $game_switches[actor_switch] = true    class_switch = $data_classes[class_choice].note[/<Class_Switch:\s*(\d*)>/].to_i    $game_switches[class_switch] = true  end
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Try getting rid of .to_i from those lines, and instead doing this:


$game_switches[actor_switch.to_i] = true


$game_switches[class_switch.to_i] = true
 

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
I tryed doing that too. No error but no switches either.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
do a

p actor_switchp class_switchto make sure you're getting what you think you're getting.Why are you removing two actors in each loop?
 

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
For some reason it was not removing the last party member.

when i printed the values this is what it returned with quotations.

"<Actor_Switch: 1>""<Class_Switch: 11>"This means its capturing everything right, not just the values?

I tried doing this and it printed 0's for both

Code:
    p actor_switch.to_i    p class_switch.to_i
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Yes. Maybe check out some other scripts that use note tags. I use them, but not the same way you are, so looking at someone else's scripts might help you out more than me explaining what I'd do (plus I'm only so-so with regular expressions).
 

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
Thanks anyways Shaz, at least I know whats going on now.

Could you maybe explain how to Gsub it out for now then convert it to an integer?

I know about it just not that much. I've never had to use it.

I figured out the problem the variables actor_switch and class_switch are equal to everything

     def remove_remaining_members        face_choice = ($game_system.face_choice + 1)        class_choice = $game_system.class_choice            $game_party.members.each_index do |i|            next if i == face_choice            $game_party.remove_actor(i)            $game_party.remove_actor($game_party.members.size) unless face_choice == $game_party.members.size        end              $game_party.members[0].change_class(class_choice, keep_exp = false)        actor_switch = $data_actors[face_choice].note[/<Actor_Switch:\s*(\d*)>/].to_i #<----- actor_switch is equal to everything        $game_switches[actor_switch] = true        class_switch = $data_classes[class_choice].note[/<Class_Switch:\s*(\d*)>/].to_i#<----- class_switch is equal to everything        $game_switches[class_switch] = true    end 
I used this with the back grounds and it works fine. could someone explain this to me?

I saw that this is how D&P3 called it in his tutorial but I am not sure if it is always the same.

  def create_class_bg    class_choice = $game_system.class_choice    $data_classes[class_choice].note[/<Background:\s*(\S\w*\s*\w*\s*\w*\s*\w*\S)>/i]    class_bg = $1 #<------ I don't know why but this is the variable it produced. Does it always produce the same one    @class_bg = Sprite.new    @class_bg.bitmap = Cache.picture(class_bg.to_s)    @class_bg.x = 0    @class_bg.y = 0    @class_bg.z = 1    @class_bg.zoom_x = (Graphics.width / 544)    @class_bg.zoom_y = (Graphics.height / 416)  end 
I tried using but it returns an error saying can't convert to string to integer

     def remove_remaining_members        face_choice = ($game_system.face_choice + 1)        class_choice = $game_system.class_choice            $game_party.members.each_index do |i|            next if i == face_choice            $game_party.remove_actor(i)            $game_party.remove_actor($game_party.members.size) unless face_choice == $game_party.members.size        end              $game_party.members[0].change_class(class_choice, keep_exp = false)        $data_actors[face_choice].note[/<Actor_Switch:\s*(\d*)>/]        actor_switch = $1        $game_switches[actor_switch] = true        $data_classes[class_choice].note[/<Class_Switch:\s*(\d*)>/]        class_switch = $1        $game_switches[class_switch] = true    endI figured it out again lol. it works fine.

here is the working def. whenever you call a note it will always return it's value to $1. Thank you for the help Shaz I guess I just had to work that one out.

Code:
     def remove_remaining_members        face_choice = ($game_system.face_choice + 1)        class_choice = $game_system.class_choice            $game_party.members.each_index do |i|            next if i == face_choice            $game_party.remove_actor(i)            $game_party.remove_actor($game_party.members.size) unless face_choice == $game_party.members.size        end              $game_party.members[0].change_class(class_choice, keep_exp = false)        $data_actors[face_choice].note[/<Actor_Switch:\s*(\d*)>/]        actor_switch = $1        $game_switches[actor_switch] = true        $data_classes[class_choice.to_i].note[/<Class_Switch:\s*(\d*)>/]        class_switch = $1        $game_switches[class_switch.to_i] = true    end
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
This is the snippet of code I use to grab notes from skills. It's in a method in the RPG::Skill class:

Code:
    @user_anim_id = 0        note.split(/[\r\n+]/).each do |line|      case line      when /<useranim\s*(\d+)>/i # <useranim 15> in note        @user_anim_id = $1.to_i      end    end
I do it like this (using a case statement) because I actually have a lot more things that I look for, and I do all of this right at the start, immediately after the default database is loaded. So every time I want to add something new to notes, I'll add an extra when statement and the handler, and I don't have to iterate through notes during the game looking to see if a particular skill (or actor, or enemy, etc) has a particular note.
 
Last edited by a moderator:

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
I will definitely keep that in mind. Thanks again Shaz.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I do it like this (using a case statement) because I actually have a lot more things that I look for, and I do all of this right at the start, immediately after the default database is loaded. So every time I want to add something new to notes, I'll add an extra when statement and the handler, and I don't have to iterate through notes during the game looking to see if a particular skill (or actor, or enemy, etc) has a particular note.
I prefer simply scanning the whole note instead of splitting on lines and iterating as it allows me to handle multi-line regex as well (with /m option). I am not sure if there are performance implications when you are scanning a 10000-character note-tag though.
 
Last edited by a moderator:

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
Can you show an example Tsukihime.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
It is just regular regex matching using Match or Scan

res = self.note.scan( Regex1 )# do stuffres = self.note.match( Regex2 )# do stuffself.note =~ Regex3# do stuffAgain, mainly so I don't have to worry about issues with multiple lines. For example, if you had a really long input and you wanted to split it up to make it look nicer in your notebox.But if you know your input is small and is not multi-line, then ya I'd go with Shaz's approach since it is faster.
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,864
Messages
1,017,056
Members
137,573
Latest member
nikisknight
Top