Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Changing the look of the player character  (Read 8817 times)

0 Members and 1 Guest are viewing this topic.

Scout

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently in development...
    • View Profile
    • Juniper Games
Changing the look of the player character
« on: March 29, 2007, 01:01:58 PM »

I did a search but didn't seem to be able to find anything on this.

How do I go about changing the look of the player character?  I have created two sets of sprites in eight directions (Bill1 and Bill2, say).  The player character starts as Bill1 but then there is an interaction which means he changes his appearance and becomes Bill2 (interacting with a wardrobe means he puts on a suit, say).  I'm sure there must be some sort of function to do this, but I'm either being very stupid or it's not obvious what I should do.

Any help, please?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Changing the look of the player character
« Reply #1 on: March 29, 2007, 02:24:11 PM »

You will need to create two actor files and simply unload the old actor and load a new one (the actors can share the same script - i.e. the "brain").

Code: WME Script
  1. // unload the original actor
  2.  
  3. // and load a new one
  4. actor = Game.LoadActor("path\bill2.actor");
  5.  
  6. // this is necessary to transfer the scene scrolling to the new actor
  7. Game.MainObject = actor;
  8.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Scout

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently in development...
    • View Profile
    • Juniper Games
Re: Changing the look of the player character
« Reply #2 on: March 29, 2007, 02:45:17 PM »

Turns out it WAS me being stupid.  :)

I got the two actor files, but it was UnloadObject bit I was missing.

Thank you so much.
Logged

sharkbait

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 13
    • View Profile
Transfer actor inventory
« Reply #3 on: March 31, 2007, 01:33:38 PM »

Unless you're using a global inventory, rather than a per-actor inventory, you may also need to transfer the old actor's items to the new one. The following is a function I wrote to handle the item transfer. It assumes that the global actor variable is called 'g_actor'. If you kept the same naming as in the demo game, you should rename it to 'actor'.

I placed the function in base.inc to have it available in all game scripts, but how you organise your scripts is obviously up to you:

Code: [Select]
function TransferActor(actorResourceName)
{
    var actorSource = g_actor;
    var actorDestination = Game.LoadActor(actorResourceName);

    Game.Msg("Actor '" + actorSource.Name + "' transfered to '" + actorDestination.Name + "'.");
    Game.InventoryObject = actorSource;
    for (var nIndex = 0; nIndex < Game.TotalNumItems; nIndex = nIndex + 1)
    {
        var item = Game.QueryItem(nIndex);
        if (item != null)
        {
            if (actorSource.HasItem(item.Name))
            {
                actorDestination.TakeItem(item.Name);
                Game.Msg("Item '" + item.Name + "' transfered.");
            }
        }
    }

    Game.InventoryObject = actorDestination;
    Game.MainObject = actorDestination;
    g_actor = actorDestination;

    Game.UnloadObject(actorSource);

    return null;
}

Note: The Game.Msg(..) calls are there for debugging purposes and you can remove them if you want.
« Last Edit: March 31, 2007, 01:36:28 PM by sharkbait »
Logged

Scout

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently in development...
    • View Profile
    • Juniper Games
Re: Changing the look of the player character
« Reply #4 on: April 02, 2007, 10:44:13 AM »

Thanks sharkbait, that's excellent.  I've filed it away for future use as I'm not sure if I'll be using a global inventory or not.
Logged

Scout

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently in development...
    • View Profile
    • Juniper Games
Re: Changing the look of the player character
« Reply #5 on: April 27, 2007, 03:33:21 PM »

You will need to create two actor files and simply unload the old actor and load a new one (the actors can share the same script - i.e. the "brain").

Code: WME Script
  1. // unload the original actor
  2.  
  3. // and load a new one
  4. actor = Game.LoadActor("path\bill2.actor");
  5.  
  6. // this is necessary to transfer the scene scrolling to the new actor
  7. Game.MainObject = actor;
  8.  


Okay, there's a development...

If I put the above code into a scene_init script it works fine (the change happens when I go from one location to another).
However, if I put this code into another object's script so that interacting with this object triggers the actor change and there is no change of location, then when I interact with other characters I get an error message - "Runtime error. Script 'actors\devlin\Devlin.script', line 14
15:16:   Call to undefined method 'Talk'. Ignored."  Yet this is only for the actor object.  The character I'm interacting with displays his dialogue as normal.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Changing the look of the player character
« Reply #6 on: April 27, 2007, 05:57:29 PM »

could you post relevant parts of the scripts?
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Scout

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently in development...
    • View Profile
    • Juniper Games
Re: Changing the look of the player character
« Reply #7 on: April 27, 2007, 07:04:00 PM »

could you post relevant parts of the scripts?

Okay.  What I have on this particular screen are two separate areas.  When you click on one of the exits the actor goes off screen, I change the actor, move the object to another place off-screen and then walk him back on in the second area.  The reason for the change is that the perspective is different and I need a second set of sprites to deal with this.  The following code is in the on "LeftClick" section of the script for the exit.
Code: WME Script
  1.         actor.GoToObject(this);
  2.         Game.Interactive = false;
  3.         Game.UnloadObject(actor);
  4.         actor = Game.LoadActor("actors\Zared_Top\Zared_Top.actor");
  5.         Game.MainObject = actor;
  6.         actor.Active = true;
  7.         actor.SkipTo(-99, 713);
  8.         actor.GoTo(109, 667);
  9.         Game.Interactive = true;
  10.  

Edit:  Okay, I've just found that if I go to another location and come back to this one the problem fixes itself and I can interact with the other characters as normal.  I don't know if that helps in any way.

Edit2:  I've just found out that the problem, although triggered by what I'm doing here, seems to be in the script for the character I'm interacting with.  In order to keep track of who's speaking I substitute variables for the actor and the character, so it reads as follows:
Code: WME Script
  1. var Tom = actor;
  2. var Bill = this;
  3.  
  4. ////////////////////////////////////////////////////////////////////////////////
  5. on "Talk"
  6. {
  7.         Game.Interactive = false;
  8.         Tom.Talk("Hi Bill.");
  9.         Bill.Talk("Hi Tom.");
  10.         Game.Interactive = true;
  11. }
  12.  
This normally works fine, but stops working for the actor character after the change.
« Last Edit: April 27, 2007, 07:39:21 PM by Scout »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Changing the look of the player character
« Reply #8 on: April 27, 2007, 07:46:02 PM »

Yup, that's it. The 'Tom' variable still references the original actor, which gets invalidated. You'd need to refresh the reference after reloading a different actor by re-assigning Tom (Tom = actor;)
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Scout

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently in development...
    • View Profile
    • Juniper Games
Re: Changing the look of the player character
« Reply #9 on: April 27, 2007, 08:16:13 PM »

Yup, that's it. The 'Tom' variable still references the original actor, which gets invalidated. You'd need to refresh the reference after reloading a different actor by re-assigning Tom (Tom = actor;)
This is the point where I get completely confused and probably why I'll never be a programmer...  I'm clearly understanding this wrongly because I thought that as it was a variable local to a script that isn't yet triggered it wouldn't be affected that way.  What am I missing? 
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Changing the look of the player character
« Reply #10 on: April 27, 2007, 08:22:43 PM »

The script is executed immediately after its owner is loaded. In this case, when 'Bill' is loaded, its script is executed. The script processes all the code outside any even handlers (in this case the two lines assigning Bill and Tom) and after that the script stays dormant in memory and it's waiting for any events to arrive.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Changing the look of the player character
« Reply #11 on: April 27, 2007, 09:35:42 PM »

Although Mnemonic explained this pretty well, I'll try to go into bigger detail what's going on:

you have here an object "actor" which occupies some memory space. As Mnemonic explained - you load the script
and everything outside the "event handlers" (those are the on "something" {} ) gets executed only once when your script gets
loaded. So this script gets executed once per scene entry. This way your leaving and returning to the scene fixed the problem
because the script got executed again which in turn again set the Tom variable to your new actor which was now valid again.

When you call Game.UnloadObject, your actor object in memory gets destroyed and together with it all references (so your variable
Tom no longer works). So your idea that you can't change the local variable from outside the script is correct, but you forgot, that
this variable points to a global object which got destroyed, so your local variable points to void place, because the space allocated for
the new object was not the same.

This is an example of the most terrible-to-find bugs ever, because if it was for example C++, you could meet a condition when the memory could be allocated in the same place so it would sometime work and sometime won't. This kind of bugs make coders to pull their hair out. :)

Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Scout

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently in development...
    • View Profile
    • Juniper Games
Re: Changing the look of the player character
« Reply #12 on: April 28, 2007, 07:34:55 AM »

Wow, thanks guys!  Your explanations are like the dawn arriving on a clear and beautiful morning.  Suddenly it all makes sense.  And I can see for miles.

Presumably, then, it's best to assign these variables, Tom and Bill, inside the event handlers?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Changing the look of the player character
« Reply #13 on: April 28, 2007, 08:58:50 AM »

Presumably, then, it's best to assign these variables, Tom and Bill, inside the event handlers?
That would work. Or, since I assume 'Tom' is your main character, you could use a global variable for him and only refresh the variable after reloading the actor. Then all the other scripts using this global variable will get the right actor reference automatically.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Scout

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently in development...
    • View Profile
    • Juniper Games
Re: Changing the look of the player character
« Reply #14 on: April 28, 2007, 04:46:24 PM »

Presumably, then, it's best to assign these variables, Tom and Bill, inside the event handlers?
That would work. Or, since I assume 'Tom' is your main character, you could use a global variable for him and only refresh the variable after reloading the actor. Then all the other scripts using this global variable will get the right actor reference automatically.
Actually, it's a bit more complex than that as I'm not only switching the animation set for the main character, but also switching between characters as the one the player controls.
Logged
 

Page created in 0.138 seconds with 25 queries.