GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Range-Finding?

Hi Guys,
I am trying to implement a Range-Finding function to facilitate AI. The problem I have is that Rule Logic Blocks only seem to allow "IF ATTRIBUTE". Currently I have a Table and Pointers set up to constrain actor X,Y positions to table cells. I was hoping to simply be able to have a constantly running AI actor that would calculate distance from one Actor to multiple others, allowing the AI to select its closest target.

The Mechanics behind doing this don't seem to hard at all, but if you'll pardon the expression... I keep getting ****-blocked by the inability of the Attribute Editor to look at a table cell value. Do I really have to make 40+ global attributes in order to "export" the table values to "Attributes"?

-Grim-

Comments

  • RThurmanRThurman Posts: 2,822Member, Sous Chef, PRO
    Could you use just one 'temp' attribute? You could reuse it every time you need to access a table value.
  • grimtoothgrimtooth Posts: 69Member
    Unfortunately I don't think one Temp attribute would work. That would disallow comparing multiple ranges to each other to find the smallest.

    Currently doing something I haven't done since junior high... Factoring Polynomials (just as fun as you remember it) will post if its a dead end when I finish I unless I get a better answer before then

    -Grim-
  • RThurmanRThurman Posts: 2,822Member, Sous Chef, PRO
    edited June 2013
    Please post it its not a dead end! I'd like to see your solution.

    It would be nice if GS Tables could hold formulas in their cells. All that comparing could be done within the table!

    Meanwhile (just brainstorming here) the new looping behavior might come in handy. It will allow you to loop "i' rows across "j" columns. Its in the nightly builds -- but could in the near future find its way into the stable release. It might be worth waiting on this aspect of your project until it's available.
  • grimtoothgrimtooth Posts: 69Member
    So here is my 2nd option I guess, instead of making 40-80 global variables to compare I could use Self.x (ATTRIBUTE) to check distance to other actors with the following super fun math.

    image
  • grimtoothgrimtooth Posts: 69Member
    OH OH, even better!

    two actors attributes, one to represent "Z^2" and I can use self.X and Self.Y in the expression editor and then store the current least distance in a 2nd actor attribute to compare against table values with a global pointer! (maybe)
  • grimtoothgrimtooth Posts: 69Member
    @RThurman I forgot to say thank you!

    You probably could have been more help if I told you that this was a tower defense project. I know that there are quality templates out there but I am still a Newbie and the learning opprotunity of failing a few times is worth more than the time saved by buying a template.

    You said "a temp variable to access table data" I said "one variable doesn't allow for comparison"

    LEARNING OPPROTUNITY and I almost missed it because I was blinded by complex math. One temp variable doesn't allow for table cell comparisons, but two (and a pointer) DO, duh

    So once again, THANK YOU and of course I'd be glad to post some of the code when finished but that might be a week or three at my current work rate hehe.

    -Grim-
  • grimtoothgrimtooth Posts: 69Member
    P.S. about your comment regarding table cells holding formulas, I couldn't agree more! And god forbid the ability it import those tables with formulae from an excel file

    In the mean time I assume we must use a "Math" actor (with attributes) to access table data, do calculations, and constrain back to the table?

    -Grim-
  • RThurmanRThurman Posts: 2,822Member, Sous Chef, PRO
    grimtooth said:

    One temp variable doesn't allow for table cell comparisons, but two (and a pointer) DO, duh

    So once again, THANK YOU and of course I'd be glad to post some of the code when finished but that might be a week or three at my current work rate hehe.

    -Grim-

    It would be great to see your solution to this interesting challenge. Post when ready!
  • RThurmanRThurman Posts: 2,822Member, Sous Chef, PRO
    grimtooth said:

    P.S. about your comment regarding table cells holding formulas, I couldn't agree more! And god forbid the ability it import those tables with formulae from an excel file

    In the mean time I assume we must use a "Math" actor (with attributes) to access table data, do calculations, and constrain back to the table?

    -Grim-

    Yes -- try to think of the 'math' actor as a substitute for a table cell that contains a formula.
  • grimtoothgrimtooth Posts: 69Member
    edited July 2013
    This is what I have come up with so far ***UNTESTED*** (need to flesh out more of the game to test.. maybe next weekend)

    image

    -Grim-
  • grimtoothgrimtooth Posts: 69Member
    And of course I already see a problem in there when I look at it as a whole... but no biggie, the Range Finding part of it works (tested with "Display Text") and that is the most important part.
  • grimtoothgrimtooth Posts: 69Member
    The Problem was that "Self.Closest.Target" is an Integer designed to store the Self.Table.Pointer value of the closest target, so instead of

    IF: Self.Range.toTarget < Self.Closest.Target

    I just now replaced "Self.Closest.Target" with a copy of the range finding equation substituting Self.Closest.Target in for Self.Table.Pointer.
  • RThurmanRThurman Posts: 2,822Member, Sous Chef, PRO
    edited July 2013
    Looks like you are on your way to solving this!

    One suggestion -- you can get rid of the extra rule and shave off a little CPU time if you increment the pointer like this:

    Change Attribute: self.Table.Pointer To: (self.Table.Pointer %30)+1

    but since the % operator is being depreciated its probably better to use the mod(x,y) function to avoid future complications:

    Change Attribute: self.Table.Pointer To: mod( self.Table.Pointer,30)+1
  • grimtoothgrimtooth Posts: 69Member
    @RThurman, if you keep answering and offering helpful advice, I'm just going to keep asking questions!!

    At this point I'm getting scared for a different reason, x# of towers running timers and y# of enemies ALSO running timers because you cannot CONSTRAIN tableCellValue TO: Self.x

    I understand now why one of my fave TD games bogs down from time to time...

    Because it is my understanding that the timer function is a bit resource intensive, I will probably replace the timers with something like:
    RULE: IF self.time = prec(self.time, 1)

    Who knows if that will work or help...

    Lunch break over, back to the daytime grind :)

    -Grim-

  • RThurmanRThurman Posts: 2,822Member, Sous Chef, PRO
    Good point about all those timers (and table referencing). Is it time to rethink things?

    There are many ways to set-up what you are trying to do. And not all of them need tables and/or timers.
  • grimtoothgrimtooth Posts: 69Member
    Just Thought that I would throw out an Epilogue to this Thread.

    I Worked hard to make this project function with the "save enemy X,Y to table and have Towers read the table for targets" line of programming. In the end it works perfectly as an exercise in what is possible, and it does not work at all as a playable game.

    What it has boiled down to is TIME. Using a modulo timer with a 0.02 global and a 0.04 iteration time it takes a tower 1.28 seconds to scan my 32 entry table, which means it can take over a second to find a target or switch targets when one moves out of range depending on the next targets position on the table.

    I don't feel that the timer can get much faster, and I chose 32 as a table size because for some of the harder waves with longer paths I really feel like there could be 32 enemies on the screen at once (if the player is failing hehe).

    I knew that Tower Defense AI can be created with collision behaviors before starting this project, but I wanted to try something new and challenging.

    For now I am just going to file the templates away and start fresh, perhaps when I have access to the Loop function it will become feasible to continue.

    -Grim-
This discussion has been closed.