Jump to content


Photo

Simple trigger question.


  • Please log in to reply
3 replies to this topic

#1 Bglamb

Bglamb

    GMC Member

  • New Member
  • 15 posts
  • Version:GM8

Posted 12 July 2012 - 01:15 PM

Ok folks, I feel like this should be an easy one, but I'm trying to work out the best way to do this and getting myself in a muddle.

I've got several instances of an object, and I want them all to run a simple piece of code at a specific time. I want this to be triggered from another object, but I'm not sure how best to do this. I hope this makes sense.

To go into more detail about what I'm doing: I have a queue of customers who will sometimes choose to leave. When one leaves, I want all of the other customers to realise that and take appropriate action (ie: move forwards if the person leaving was in front of them). So ideally I want that person to shout out "I'm leaving, and I was in position 4", and for all the other customers to be listening out for that shout. They will then check if their position is greater than 4, and move forward appropriately.

Many thanks.
  • 0

#2 TsukaYuriko

TsukaYuriko

    GMC Member

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

Posted 12 July 2012 - 01:17 PM

You're probably looking for with. Pseudo-code example:
if (the_customer_leaves) {
    with (obj_customer) {
        if (position > 4) move_forward_appropriately();
        }
    }

  • 1

#3 filulilus

filulilus

    GMC Member

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

Posted 12 July 2012 - 01:23 PM

Use "with" and "other", they are so d*mn usefull it's unbelivable.
By using "with" followed by the name of the object (or instance id) you can execute code with ALL the instances of that object.
With "other" you can get values from the instance that called the "with".

Example, obj_ctrl will tell obj_customer to move forward IF they have a larger "queue value" then the customer who left:
queue_left = 5
with obj_customer
{
if queue_value > other.queue_left
{
queue_value -= 1
//move forward
}
}

Edited by filulilus, 12 July 2012 - 01:24 PM.

  • 1

#4 Bglamb

Bglamb

    GMC Member

  • New Member
  • 15 posts
  • Version:GM8

Posted 12 July 2012 - 02:07 PM

Aha, I knew it would be simple.

That's superb. Thanks to you both!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users