Jump to content


Photo

Array wont store an object?


  • Please log in to reply
2 replies to this topic

#1 batlord

batlord

    GMC Member

  • GMC Member
  • 130 posts

Posted 09 January 2011 - 05:05 PM

Hello , I am using an array to fill a 2D array with object data so I have three objects (object0,object1,object2)

scr_fill_array ==> a script
var i,j;
for (i=0,i<=480;i+=1)
{
  for (j=0,j<=480;j+=1)
  {
    arr[j,i] = argument0;
  }
}

in object0 create event:
arr[640,480] = object1;
script_execute(scr_fill_array,object1); //To make sure that all of the array's indexes are full in object data (object1 is the defult of the array)

in object2 keypress space
script_execute(scr_fill_array,object2);

and the debugging shows that before I press space the
object0.arr[300,300]
is equal to 1 and after I press space it's still equal to 1 "It should have become 2".

I would really appreciate any help you would provide.
  • 0

#2 desertdweller

desertdweller

    Love Truth

  • New Member
  • 1255 posts

Posted 09 January 2011 - 05:14 PM

script_execute() acts locally right now, so it only sets the array values for "arr" in the object that calls the script.

In your case, object0's create event sets the "arr" values correctly, but then object2 sets them for its own local array "arr".

You could solve this by placing a big with {} bracket around the entire script, so scr_fill_array would look like:

with (object0)
{
var i,j;
for (i=0,i<=480;i+=1)
{
  for (j=0,j<=480;j+=1)
  {
    arr[j,i] = argument0;
  }
}
}

That way the arr[] values will always be in object0.
  • 0

#3 batlord

batlord

    GMC Member

  • GMC Member
  • 130 posts

Posted 09 January 2011 - 07:02 PM

Thank you
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users