Last Object

BlueFanStudiosBlueFanStudios Member Posts: 77
edited November -1 in Working with GS (Mac)
How can I determine the most recently created object? im sure ive seen it before

Comments

  • RedlerTechRedlerTech Member Posts: 1,583
    Create a text attribute called recent. Have in all actors this behavior

    Change attribute: game.recent to self.name

    This way, when you spawn new actors that attribute will automatically become their name.

    Matt :D
  • BlueFanStudiosBlueFanStudios Member Posts: 77
    thanks Matt, we've tried that and its not working. Ill explain in more detail.

    We have a series of random objects spawning from the right side of the screen and moving across to the left. Those objects speed increases based on the score of the game.

    What we want to do is determine the distance between the last object to spawn and the spawn point, so that when the object has moved a certain distance it will spawn another. Keeping the distance between all objects equal despite the increasing speed.

    Is that possible??
  • RedlerTechRedlerTech Member Posts: 1,583
    ahh yes :D

    Interesting and possible :D

    Okay first

    Create the following attributes:
    SpawnX - Real - Make it the X position of where you spawn
    SpawnY - Real - Make it the Y position of where you spawn
    DistanceFrom- Real
    Last - Text

    Put in all your actors that are spawned:
    Attribute - Boolean - "Last"

    Change attribute - self.name to random(1,9999)
    Change attribute - game.Last to self.name
    Rule: If self.name = game.Last, change self.Last to true.
    Rule: If self.Last is true, Constrain Attribute game.DistanceFrom to magnitude(self.position.x-game.SpawnX, self.position.Y-game.SpawnY)
    Rule: If game.DistanceFrom < X (make it a number lol) spawn actor

    Enjoy :D

    ________________________________
    1 On 1 Project Help - Matthewredler@gmail.com
  • BlueFanStudiosBlueFanStudios Member Posts: 77
    do you have the pro version? would it make a difference??
  • RedlerTechRedlerTech Member Posts: 1,583
    Can you explain what you mean by that? I am a pro member to GameSalad if that's what you're asking.

    Matt
  • BlueFanStudiosBlueFanStudios Member Posts: 77
    I put that in, but I can't check if self.name = game.last, because they are text variables. Also, GS seems to crash when I try to run it with this code.
  • RedlerTechRedlerTech Member Posts: 1,583
    Ahh try making game.Last an integer.

    Matt
  • BlueFanStudiosBlueFanStudios Member Posts: 77
    Tried that, Gamesalad crashes everytime I run the game though :(
  • RedlerTechRedlerTech Member Posts: 1,583
    I really don't know. The code is right. Is it crashing on the viewer, in an adhoc, or on the viewer?
  • BlueFanStudiosBlueFanStudios Member Posts: 77
    Just when I click preview on gamesalad.
  • RedlerTechRedlerTech Member Posts: 1,583
    That is something with GS, try building an adhoc.

    Matt
  • BlueFanStudiosBlueFanStudios Member Posts: 77
    No luck at all, unfortunately. We have another method of doing this but it's a bit messy, worst comes to worst we will just use that. Thanks for your help though, it's really appreciated.
  • RedlerTechRedlerTech Member Posts: 1,583
    not a problem, sorry for the inconvenience.

    Matt
  • old_kipperold_kipper Member Posts: 1,420
    for the determining of if the object is last I would try putting in a game attribute integer set at zero and each actor has rules in that add 1 to that integer then taking game attribute integer number as a self ID in a self integer attribute. Then check to see if their self number is less than the game integer, and (in another rule) equal to,and so know they were the last actor and with the first rule will update themselves if they fall out of being last.

    I've tested it and it seems to work

    http://imageshack.us/photo/my-images/16/lastactor.png/

    the second aspect of your question would be to add 1 more self number attribute and a boolean for checking of the spawning. On birth put self position x into the new x self attribute, and then run a rule that says then when boolean is false, and the coordinates are greater than the stored x + whatever, then spawn and change the boolean to true.
Sign In or Register to comment.