Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: how to store multiple actors into array?  (Read 2817 times)

0 Members and 1 Guest are viewing this topic.

yaobifeng

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 24
    • View Profile
how to store multiple actors into array?
« on: April 29, 2008, 07:55:22 AM »

hi guys,i want to track  multiple actors in the scene.i define a global variable in the base.inc file like this:
global  actors = new Array();

then for a test ,i load a actor in the "LeftClick" function like this:

var actor1;
actor1=Game.LoadActor3D("actors\victor\victor.act3d");   
actors.Push(actor1); 
Game.Msg(actors.Length);

when i click the mouse more than one time, i found actors.Length always is 1.
why?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: how to store multiple actors into array?
« Reply #1 on: April 30, 2008, 01:45:39 PM »

NEVER put something like this to base.inc. These inc files are simply included into other source files. It means everytime you run some script referencing base.inc, a new array is created.
Change it to something like this:

global actors;
if(actors == null) actors = new Array();

That way the variable is only initialized once.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

yaobifeng

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 24
    • View Profile
Re: how to store multiple actors into array?
« Reply #2 on: May 02, 2008, 11:17:23 AM »

It's ok,thanks very much.
Logged
 

Page created in 0.026 seconds with 19 queries.