Need help: Differentiating Duplicate Actors

RocketBrainRocketBrain Member, PRO Posts: 269
edited November -1 in Working with GS (Mac)
Hey all, i'm still trying to make a tower defense game and having trouble determining targeting patterns. I've tried overlap targeting and range targeting. I've gotten both to work....kind of.

The issue i'm having is getting the Actors to not share the same targeting booleans and targeting coordinates.

So lets say i have two actors. Gun & Target. I can get the gun to only fire at the target when its in range. However when i place a second gun thats out of range....it fires at the target thats overlapped the first gun, even though its out of range.

So as far as i can tell i can alleviate the issue if i can get the game to recognize and assign identification of ;actors that are duplicated.

And no, creating multiple actors is not an option. ie: gun1, gun2, gun3

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Give the gun actor a self integer attribute called ID. Then you can go into each gun instance and change the value of the integer without unlocking the instance. Give each gun a unique integer ID. Then you can do the same for the targets. What you will need to do though is have separate game attributes for the target x and y. So then you can have a rule in the target like this:

    if self.ID=2
    constrain game.target2x to self.positionX
    constrain game.target2y to self.positionY

    then in the gun have a rule that says
    if self.ID=2
    and self.magnitudeBetweenGunandTarget2 < 50 (you'll have to create this and set it up using the magnitude function)
    change self.StartFiring to True
  • RocketBrainRocketBrain Member, PRO Posts: 269
    Sci, is that assuming theres a limited number of targets, instead of like the Gun? what determines what the unique id is?

    TSB, if i use self attributes how do i get the gun to see what self attributes are in the target?
  • RocketBrainRocketBrain Member, PRO Posts: 269
    ?
  • RocketBrainRocketBrain Member, PRO Posts: 269
    So how do i communicate self attributes between actors without using a standard game attribute? is it possible? wish i could "send" a message directly at one actor without knowing its name lol.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    well the good news is i found a way to circumvent the issue but its causing a gazillion times more work.
  • okkleokkle Member Posts: 32
    RabidWeasel said:
    So how do i communicate self attributes between actors without using a standard game attribute? is it possible? wish i could "send" a message directly at one actor without knowing its name lol.

    I haven't tested this out, but I think this is what you need to do:

    Assign a self attribute to the gun actor called 'active'.

    You'll then need to set up a rule in the gun that says if the enemy is within the gun range self.active is true, otherwise it equals false.

    Then make the rule that if the gun's self.active = true, do all the stuff you currently have to make it fire.

    So the 'active' attribute is only true if a target is within it's range, so the second gun should not start shooting until it's own 'active' attribute is set to true.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    looking at that now.

    my circumvent was to create a grid of boxes that the gun would shoot at if the targets overlapped. and if the targets themselves got hit in the path of the shot then they'd be destroyed. the grid wouldnt go anywhere.

    however looking at what it would require to make a grid accurate enough to make it believable would be 1,628 actors (not counting guns and targets). My system used 4 game level attributes per grid unit as well as 3 self attributes. lol lets avoid that.
  • okkleokkle Member Posts: 32
    I just noticed a typo it should be self.active not self.attribute lol, have edited it now.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    that still doesnt alleviate the problem if you have more than one gun and target....

    works great if you have one gun and lots of targets or lots of guns and one target but not both.
  • okkleokkle Member Posts: 32
    Hhhm it's hard to say without actually see it all in action sorry. So what happens now with one enemy and two guns? Does each gun only fire when the enemy is within it's own range?

    What exactly happens when you have one gun with multiple enemies?
  • RocketBrainRocketBrain Member, PRO Posts: 269
    the problem is telling the gun/guns who to target. using a game level x/y for the target makes it so it only updates the first target. but using a self attribute the gun cant see.

    the same works for the gun x/y since each target will only calculate one range to one gun. the others just get ignored.

    what i need is a way to say. if ANY target enters range of Gun shoot at it. but communicating the coordinates for one specific target seems to be out of GS capabilities.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    i think i need a rule in the gun that tells ONLY the target thats in range to send the gun its specific coordinates without using a game level attribute.

    it would be so much easier if i could figure out a way for the targets to uniquely identify themselves as soon as they were generated and then the gun can say, if any target is in my range match my ID to match its ID then request coordinates and fire.

    i think thats kinda what scitunes was getting at but...its proving difficult.
  • okkleokkle Member Posts: 32
    Can you not do that by giving the targets some new self attributes too?

    They could uniquely identify themselves by having a global attribute called say 'enemySpawnCount' and every time a target is spawned it adds one to that enemy count, then tells itself to set it's own ID to that enemy count. So I guess you have an attribute that keeps track of the number of targets currently on screen, whilst this count the total number spawned across the entire length of the game.

    So the first target to spawn will set game.enemySpawnCount to 1 and then set it's own self.ID to 1, the next to spawn add +1 to game.enemySpawnCount again making it 2 and then it's own self.ID to 2 and so on.

    Then you could link that ID up to the gun when the target comes into it's range as you suggested.

    What I found helped when I was making my game was after I'd got a basic thing working to a degree and figured out exactly everything I would need to trigger events etc. I wrote it all down and started fresh from the notes I'd made. As I found going back and editing rules here and there was getting messy and confusing.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    nope...still have to communicate the target id to a specific gun. if you use the game level id (which with GS is the only way to communicate info back and forth between actors) you end up changing all of the gun/target attributes.

    The gun cant directly look inside the target for an attribute.
  • okkleokkle Member Posts: 32
    Ah yes I see what you're saying. Self attributes can only be read by that one actor with that attribute and you need a different actor to be able to read it.

    That is a really tricky one. I have to concede, I really don't know I'm sorry. I'm sure there must be a way, but it's beyond my skills.
Sign In or Register to comment.