Jump to content


Photo

Question about the 'other.' function


  • Please log in to reply
4 replies to this topic

#1 Zealot644

Zealot644

    GMC Member

  • New Member
  • 266 posts
  • Version:GM8

Posted 26 February 2012 - 10:10 PM

I am trying to check something, and then perform an action based off of another objects variable. Current code is as follows:

if place_meeting(x,y,obj_tparent) = true //If obj_rightclick_button is over obj_tower parent
if global.player_money > (50*other.tower_ratio)    //If the player's money is X amount based on a variable on the applicable tower

Basically it checks for the parent of obj_tower which is named obj_tparent. This allows me to set all towers to have the parent of obj_tparent and have any collision checks apply to each one. What I need though, is a specific way to use a variable from the specific tower in which collision is occurring. To do that, I have attempted the use of other.tower_ratio, but it doesnt work and keeps telling me that it is an unknown variable. From what I can tell, the other. variable can only refer to another event within the same object, in this case obj_rightclick_button, but cannot refer to another object entirely.

Assuming that makes sense, does anybody know a way to pull a variable out of another object that collision has occured with? I would have used global.tower_ratio, but I am fairly certain that if I were to use that then I could not have individual ratios (Basically, prices) for different towers in my game.

Let me know if you need clarification of anything - thanks in advance.
  • 0

#2 thegame

thegame

    Flying Penguin

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

Posted 26 February 2012 - 10:15 PM

The other keyword only works in a) with statements and B) collision events.
What you want to do is use
var inst;
inst = instance_place(x,y,obj_tparent);
if(inst) {
  if(global.player_money > (50 * inst.tower_ratio) {
    /*blah blah blah...*/
  }
}

  • 1

#3 Zealot644

Zealot644

    GMC Member

  • New Member
  • 266 posts
  • Version:GM8

Posted 26 February 2012 - 10:24 PM

The other keyword only works in a) with statements and B) collision events.
What you want to do is use

var inst;
inst = instance_place(x,y,obj_tparent);
if(inst) {
  if(global.player_money > (50 * inst.tower_ratio) {
    /*blah blah blah...*/
  }
}


So, with instance_place referring to obj_tparent, it would pull the required variables and such out of ONLY the tower that collision was true with, not from every tower?
  • 0

#4 thegame

thegame

    Flying Penguin

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

Posted 26 February 2012 - 10:37 PM

instance_place returns the found object's id, and this id can be used to access the variables, just like the other keyword or an object's index. It can also be used in the with() statement. By getting only the tower at the place you want to find it, you will only be able to get that tower's variables
  • 0

#5 Zealot644

Zealot644

    GMC Member

  • New Member
  • 266 posts
  • Version:GM8

Posted 27 February 2012 - 03:06 AM

instance_place returns the found object's id, and this id can be used to access the variables, just like the other keyword or an object's index. It can also be used in the with() statement. By getting only the tower at the place you want to find it, you will only be able to get that tower's variables


Alright. Thank you!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users