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: Multiple of the same actors issue  (Read 10642 times)

0 Members and 2 Guests are viewing this topic.

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 302
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Multiple of the same actors issue
« on: August 12, 2012, 08:41:34 AM »

Basically a player can create multiple of the same actors, which are dogs. I do the DogActor = Game.LoadActor("actors\Dog\Dog.actor"); script every time the player wants to create a new dog and add it to the scene, it can do that. The problem is that I want the player to be able to click on a dog, select it, then click on a spot to make the dog walk to another point in the scene. However, when I click somewhere, all the dogs walk to the same area since they share the same script. Is there a way to select one of the dogs and make that individual one walk to a certain point, while sharing the same script and variable name as the other ones? Maybe I can somehow dynamically create a actor so its like var DogActor = DogActor +1;  ? If so, then what would be the best way to handle when the player clicks on the dog he wants to move?

Sorry this is a weird question, but it will make sense if someone places the game lol :)
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: Multiple of the same actors issue
« Reply #1 on: August 12, 2012, 09:04:30 AM »

this shouldn't be happening. I presume you have some weird script attached.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 302
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: Multiple of the same actors issue
« Reply #2 on: August 13, 2012, 05:00:33 AM »

I use this code:

On "LeftClick"

{
DogSelected = true;
}

Then to handle the click I do

if(DogSelected==true)

{
DogActor.Skipto(Game.MouseX,Game.MouseY);
}


It makes all the dogs in the scene go to the area, not just the selected one.
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Multiple of the same actors issue
« Reply #3 on: August 14, 2012, 03:26:48 PM »

Yes but where do you define DogActor? You could do something like:

Code: WME Script
  1. On "LeftClick"
  2. {
  3.   DogSelected = true;
  4.   DogActor = this;
  5. }
  6.  
Logged

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 302
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: Multiple of the same actors issue
« Reply #4 on: August 15, 2012, 01:06:48 AM »

anarchist, thanks. my next question is, say I want click on one dog, then click on another, so 2 will be selected. Then I click on an area and the 2 dogs will go to the same place. Any idea how to do that? Thanks dude.
Logged

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Multiple of the same actors issue
« Reply #5 on: August 15, 2012, 07:19:27 AM »

Not tested but:

Dog's script:
Code: WME Script
  1.  
  2. this.SelectedByUser = false;
  3.  
  4. on "LeftClick"
  5. {
  6. if (this.SelectedByUser) this.SelectedByUser = false//Deselect the dog, if selected
  7. else this.SelectedByUser = true//Select the Dog, if not selected
  8. }
  9.  
  10. method MoveDogsToPosition(GoX, GoY)
  11. {
  12. if (this.SelectedByUser) this.GoTo(GoX, GoY);
  13. }
  14.  

And where you control the click for moving the dogs:
Code: WME Script
  1. on "LeftClick"
  2. {
  3. DogActor.MoveDogsToPosition(Game.MouseX, Game.MouseY);
  4. }
  5.  

As said before it's not tested and probably it can be improved, but it should work ;)
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Multiple of the same actors issue
« Reply #6 on: August 15, 2012, 04:18:11 PM »


And where you control the click for moving the dogs:
Code: WME Script
  1. on "LeftClick"
  2. {
  3. DogActor.MoveDogsToPosition(Game.MouseX, Game.MouseY);
  4. }
  5.  

Good thought but you need to call this method for all DogActor objects. piagent you cannot use a single variable for this. You need to store each actor in a separate variable (or in an array) or another way would be to name the actors as "Dog1", "Dog2" etc. and loop on Scene.GetFreeNode:

Code: WME Script
  1. on "LeftClick"
  2. {
  3.   for(var i = 1; i <= DOG_NUMBER; i = i + 1){
  4.      DogActor = Scene.GetFreeNode("Dog" + i);
  5.      if(DogActor != null) DogActor.MoveDogsToPosition(Game.MouseX, Game.MouseY);
  6. }
  7.  
Logged

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Multiple of the same actors issue
« Reply #7 on: August 15, 2012, 07:06:24 PM »

Since he load an actor all the dogs actor should have the same name, i think that's why all the dogs move at the same time.

So if you call a method it should be called for all dogs.
Logged

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 302
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: Multiple of the same actors issue
« Reply #8 on: August 18, 2012, 11:25:44 PM »

Thanks guys... although, I dont seem to be having any luck with this :(
Logged

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1456
  • Lamp dog!
    • View Profile
Re: Multiple of the same actors issue
« Reply #9 on: August 19, 2012, 11:21:16 AM »

Best solution is to upload the sources of a little project.
Logged
fl*p

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re: Multiple of the same actors issue
« Reply #10 on: August 21, 2012, 11:10:01 AM »

Hi piagent,

ok, I only made some tiny changes. As I can't say what your goals might be, this surely is no complete solution (I ignored the Street scene at all) - but it should get you started!

Running this altered version should show you the room scene with five Mollys which you can select by clicking. By clicking into the scene, the selected Molly will walk there.

http://wme.jerrot.de/support/multipleactors.zip

These are my changes:

scripts/scene.script
I just changed that back to the original version of the demo, your changes were not needed there.

actors/molly/molly.script
All I do in the "LeftClick" event is setting the global variable "actor" to "this".
So on LeftClick, the current actor will change. Moving the current actor is handled by the original scene.script already.
I also set the Game.MainObject to the current actor, so that scene scrolling will work on the selected Molly/dog.

scripts/game.script
I just commented out the creation of Molly here, because I create all the dogs/mollys in the scene_init.script of the Room scene.

scenes/room/scr/scene_init.script
This is, where all the "magic" actually happens. I deleted all unnecessary stuff for this demo (like the old guy, hints, etc) to shorten the file for easier understanding of my changes. Here I create 5 dogs/Mollys in a for-loop on-the-fly and assign them a position in the room. After that, I simply assign the first dog to be the current "actor" (and also the Game.MainObject).

Where to go from here?
I made the "dogs" variable global to be able to address dogs from other scripts, although this is not needed for this demo.
I don't know if you want to use those dogs in different scenes, so after all it might be more useful for you to load the actors in the game.script and not in this specific scene_init.script. In this case, you could use that global "dogs" variable and just iterate over them (with a for-loop, the same way I created the dogs) to assign them particular positions, etc. in every scene_init.script where you want to have them.

And that's it, hope it helps.
Logged
Mooh!

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 302
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: Multiple of the same actors issue
« Reply #11 on: August 23, 2012, 05:36:26 AM »

Thanks so much Jerrot ! I will get to work on this.
Logged
 

Page created in 0.178 seconds with 22 queries.