Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

A scripting question about changing actors

Hi, I'm just beginning to learn and I wanted to ask how do you change actors using a script?
I'm trying to make a Digivolution script that acts just like in Digimon World X (Digimon Wolrd 4) where there is a menu of choosing which Digimon you want to digivolve.

Anyways, I have this code, which is part of an even larger code:
Code:
when 0 #evolve
      $game_system.se_play($data_system.decision_se)
      if $game_actors[2] != $evolution[i].character

I do not know if it is right, but it is part of the code for choosing the evolve command from a menu. I wanted to make it so that if the second game actor (which is the main Digimon actor) is not the same as the evolution's character actor, it would become that actor, otherwise the evolve option would not be selectable.  I hope that made some sense, anyway, I'm just beginning to script...
 

khmp

Sponsor

It looks from the code snippet like you have the right idea. But its hard to gather a whole lot from 2 lines of code. There is a difference between character and actor though. A character holds all the pertinent information for drawing a Event or the Player on screen. An actor holds all the goodies like stats. So your comparison might need to change unless I'm missing something. Truly though I wish you lots of luck with your script. Few people start with such a large project.

Good luck with it Sakura Martinez! :thumb:
 
but is the general idea of that part of the code which checks if the actor is the same as the one stored in evolution correct?  Also, I still do not know how to change that actor into the actor stored in evolution.  I'm thinking of calling a common event for that, but I do not know how to call a common event in a script as well.  So if anyone can teach me about that and explain to me how to do it, then that would help a lot.

I really wanted to learn how to do this and finish this script.
 
Well, I don't know about changing the actor, but you could just use:

Code:
$game_party.remove_actor(actor_id)

and

Code:
$game_party.add_actor(actor_id)

I don't know if that is the same as "changing" but it is "replacing".
 
About that code, can I use it like this:
Code:
when 0 #evolve
	$game_system.se_play($data_system.decision_se)
	if $game_actors[2] != $evolution[i].character
		$game_party.remove_actor(2)
		$evolution[i].character.add_actor

I've defined the attr_accessor:character of evolution as 'character', then I have this code:
Code:
def initialize(name, image, character)
	@name = name
	@image = image
             @character = $game_actors[actor_id]

Is this correct?
Now, maybe someone can help me with that calling "common events in script" thing.
 

khmp

Sponsor

# If On Map : Replace id with common event id
$game_temp.common_event_id = id

# If in Battle : Replace id with common event id
common_event = $data_common_events[id]
$game_system.battle_interpreter.setup(common_event.list, 0)
 

khmp

Sponsor

Sakura Martinez":1uiurefr said:
About that code, can I use it like this:
Code:
when 0 #evolve
	$game_system.se_play($data_system.decision_se)
	if $game_actors[2] != $evolution[i].character
		$game_party.remove_actor(2)
		$evolution[i].character.add_actor

I've defined the attr_accessor:character of evolution as 'character', then I have this code:
Code:
def initialize(name, image, character)
	@name = name
	@image = image
             @character = $game_actors[actor_id]

When you remove the actor from the party like that you must put someone in his place. And with the methods $game_party.remove_actor and $game_party.add_actor you remove an actor from anywhere in the party but put the new actor at the end. Like for example you have the array of actors like this [actor1, actor2, actor3] with remove_actor you remove actor2. So now the array is like this [actor1, actor3] Now if you re-add a new actor2 into the party using add_actor your array is this [actor1, actor3, actor2] You need a new method to insert actor2 into the same position as actor2. I assume that's the effect you are looking for. The method would be just a replacement of data.
Code:
class Game_Party
  def replace_actor(actor_id, replace_id)
    # Determine where the actor that will be replaced is located.
    index = $game_party.index($game_actors[actor_id])

    # Return if there is no actor currently fitting that description.
    return if index.nil?

    # Replace the actor
    $game_party.actors[index] = $game_actors[replace_id]
  end
end

Also you want to stick with manipulating game_party. You shouldn't remove an actor from the party and then add an actor into the evolution. I'm confused by what exactly evolution's purpose is. Is it meant to hold the same information as $game_actors or...?

As for the rest of it I think you can use that code like that. But again its hard to grasp a whole lot from small amounts of code. Its likes looking at a shoebox but never allowed to look inside.

Good luck with it Sakura Martinez! :thumb:
 
Well, the actor to be replaced is the predefined actor 2 in the database and the replacing actor varies from what the player chooses, so I can't really use a specific actor id, that's why I defined 'evolution' and made it have the second code I posted since the developer would be allowed to create their own evolutions by creating an event and calling a script with these codes:

$evolution[0] = Evolution.new("Name of Evolution", "Picture of the Digimon/anything to evolve to" , <the game actor's of the evolution)

so it what character it would digivolve to would depend on what the game developer specified by the above code, which adds that particular evolution to the list of possible evolutions.

What I had been trying to do is that when the player chooses to evolve to the evolution defined in $evolution[0] he would be replaced by an actor that has already been created from in RMXP's actor database.

what shoudl be written on the code below $game_party.remove_actor(2) if $evolution.character is defined as the actor in $evolution?

Code:
when 0 #choosing yes in the evolution command
   $game_system.se_play($data_system.decision.se)
   if $game_actors[2] != $evolution[i].character #if game actor is not the same as the game actor stored
                                                                  in $evolution[i].character
        $game_party.remove_actor(2)
   
 

khmp

Sponsor

Alright thanks for that run down. I think you should change the term "character" to "actor". Its a lot less confusion to us scripters as we have a predisposition to what the words mean when it comes to RGSS. A "character" like I explained above is all the data relative to drawing him during Scene_Map. Whereas an "actor" is all the behind the scenes stuff like stats and battler information. And you might be better off just holding the ID of the actor involved in the evolution. No need to have an entire copy of the actor as you can get all the data you will need based on an actor ID(4 bytes).

Code:
when 0 # evolve
  # If the monster has already evolved into this form.
  if $game_actors[actor_id] == $game_actors[$evolution[actor_id].actor_id]
    # Play the buzzer SE
    $game_system.se_play($data_system.buzzer_se)
    return
  end

  # If we have reached here there should be no problem in character replacement.
  $game_system.se_play($data_system.decision_se)
  # Replace the actor.
  $game_party.replace_actor(actor_id, $evolution[actor_id].actor_id)

I'm making the assumption that you would want to do this in battle. In which case the @active battler.id will decide who and what happens. That code also makes the assumption you would use an ID instead of an entire actor. With the actor comparison instead:
Code:
when 0 # evolve
  # If the monster has already evolved into this form.
  if $game_actors[actor_id] == $evolution[actor_id].character
    # Play the buzzer SE
    $game_system.se_play($data_system.buzzer_se)
    return
  end

  # If we have reached here there should be no problem in character replacement.
  $game_system.se_play($data_system.decision_se)
  # Replace the actor.
  $game_party.replace_actor(actor_id, $evolution[actor_id].character.id)

It also makes use of that actor replace method I made above somewhere.

One final thing and its ok if you say no or ignore me outright :wink:. Could you also not spoiler code? For some reason I can't see them in RGSS Support topics I have to quote or modify your post to realize they are even there.

Good luck with it Sakura Martinez! :thumb:
 
I see...
Thanks for that.
I'm still learning so I didn't knew about that.  Anyways, I'll change the character to actor in my script.  I'm not actually going to use this in-battle, since I am trying to recreate the evolution method used in the Ps2 game Digimon World 4.
 

khmp

Sponsor

Its nice to do something for others. So I wish you lots of luck with your script. If you have any further questions about it just give a shout.

And as always good luck with it Sakura Martinez! :thumb:
 
I want to go back with the question of calling and triggering common events inside a script.
I've followed this:

Code:
common_event = $data_common_events[id]
$game_system.battle_interpreter.setup(common_event.list, 0)

changing it to:
common_event = $data_common_events[0]
$game_system.battle_interpreter.setup(common_event.list, 0)

and when I test it, I get an error saying:

line 186: NoMethodError occured
undefined method 'list' for nil:NilClass

when I go to check the script, this is line 186:
Code:
$game_system.battle_interpreter.setup(common_event.list, 0)
 

khmp

Sponsor

I think I know why but let me know if its wrong. Common events like everything else in the database start at index 1. So when you go to create common event index 0 its yelling because there is nothing at that index. So basically 1 or higher.

Good luck with it Sakura Martinez! :thumb:
 
oh, lol... I thought it was like the game_actors where it starts with 0.
I changed common_event = $data_common_events[0] to common_event = $data_common_event[1] and now it gives me a one line error:

Syntax error occured while running the script
 

khmp

Sponsor

Umm maybe I've misread something and not telling you to go in the right direction. You want to call a common_event within a script? Like in Scene_Menu or Scene_Title? Or through an event on the map or in battle? Outside of Scene_Map and Scene_Battle there is no interpreter running. Their instance exists but they aren't being updated. Or at least I think that's how it works. Not sure about the error though. Would you be willing to create a demo to showcase the problem? I'm sort of out of ideas sorry. If you are worried about privacy you can PM me the link. Or if that's not acceptable. I can only keep punching in the dark and hope for a hit. But we've seen that I'm very unlucky in that field. :wink:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top