Jump to content


Photo

Find next value when checking all objects?


  • Please log in to reply
6 replies to this topic

#1 Hello Darren

Hello Darren

    Pirate

  • Banned Users
  • 275 posts
  • Version:Unknown

Posted 04 March 2012 - 02:56 PM

I have a door object that has a variable called var_Exit that numbers up to 15. Now when the door object is created I want it so that variable is automatically created but the value must not have already been taken. So for example, when you first create a door it's var_Exit will be 0, the next door will be 1, then 2, etc. But you can also delete doors so it will need to check to make sure of previous numbers.

How would I go about doing this? I was thinking of using with(obj_Door) then checking to see what the lowest var_Exit number is free then assigning it but I don't know how to do this.

Edited by Hello Darren, 04 March 2012 - 05:58 PM.


#2 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5586 posts
  • Version:GM:Studio

Posted 04 March 2012 - 04:28 PM

var i; i=0;
with(obj_door){ var_Exit=i; i+=1; }

they do that code in order by the door created first get to do the code first, I'm using a var variable since it will be global in the script, and not exist when it is done .. otherwise you would have to do it like so:
i=0;
with(obj_door){ var_Exit=other.i; other.i+=1; } // where other does refer back to the object telling all the doors to do the code

  • 1

#3 Hello Darren

Hello Darren

    Pirate

  • Banned Users
  • 275 posts
  • Version:Unknown

Posted 04 March 2012 - 04:38 PM

The problem is that the doors can be created and destroyed at any time so it would need to specifically check if the value hasn't been taken when it's created and 'delete' the value when the object is destroyed thus freeing that value again so could be taken.

#4 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5586 posts
  • Version:GM:Studio

Posted 04 March 2012 - 04:50 PM

well, I use to give the door the number, then check if it have been unlocked earlier:

room creation code:

var i;
i=0; // <- if you want doors in another room to start from a diffrent nr, then just change it here
with(obj_door){
  var_Exit=i;
  if global.unlocked[var_Exit] instance_destroy()
  i+=1;
}
after that I don't run the code again, so there is no problem that some other door take over the number ..

unless you want to do some rapid door creation/deletion .. (level editor?)

and when you open the door you just change: global.unlocked[var_Exit]=true;
  • 1

#5 Hello Darren

Hello Darren

    Pirate

  • Banned Users
  • 275 posts
  • Version:Unknown

Posted 04 March 2012 - 04:57 PM

Yeah the doors are being created/destroyed mid-level so it all needs to be done inside the object when it's created/destroyed.

#6 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5586 posts
  • Version:GM:Studio

Posted 04 March 2012 - 05:10 PM

well, then you can do it like this, in the room creation code:
global.count = 0

door create event:
var_Exit=global.count;
global.count+=1;

that way the new door always get a number 1 higher, I'm unsure how far you want to take it tho' do you need to leave the level and come back with the doors still there? .. or is it some random generation / timeline thing?
  • 1

#7 Hello Darren

Hello Darren

    Pirate

  • Banned Users
  • 275 posts
  • Version:Unknown

Posted 04 March 2012 - 05:58 PM

Okay thanks. I created an array and stored the data in that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users