playMaker

Author Topic: raycast, getting error because of infinite loop that doesnt exist  (Read 5542 times)

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
I made a "raycast" with a "bool test" of the "Store Did Hit" bool, so i can have actions for both cases (hit and not hit). The raycast gets repeated for all my sphere "game objects" in the level without a "wait" inbetween. But that results in a "infinite loop" error and my script stops. Even though its clearly not a loop because when i use a "wait" it cycles through all my gameobjects just fine, having a wait in it is too slow though.

Im also wondering why there is only a "hit event" in the raycast parameters and no "not hit event"? Without the bool test i use it would then simply have to stop when the ray doesnt hit.
« Last Edit: June 19, 2012, 12:19:15 PM by Davision »

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #1 on: June 19, 2012, 12:31:20 PM »
to negate such a scenario, simply add a send event action right below the raycast action. That way it'll first check if the raycast hit, send an event if it hit and leave the state, or not send an event, finishing the raycast action and only then doing the send event action. So unless the raycast does not hit, the send event will be used, which will then be equal to your not hit event. This little trick can save you gazilions of unneded bools :D

I would at first whim say there really is an infinite loop in your fsm, just because I thought the same as you a thousand times and was proven wrong each and every time :S
Best,
Sven

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #2 on: June 19, 2012, 01:00:44 PM »
That trick let it run through some more objects before it gives the infinite loop error. But unfortunately not enough, i have 49 objects and it goes through 39 now.
I know for sure that its not a loop because with the "wait" it goes into the end state i made. I might also need to mention that both "hit" and "not hit" keep the loop going, til all objects have a ray casted.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #3 on: June 19, 2012, 10:38:29 PM »
Hi,

 How do you loop through your objects? I am not sure why you need to raycast to so many objects. Could you describe what you intend to do? I suspect you could simplify the process using triggers.

 Bye,

 Jean

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #4 on: June 20, 2012, 05:20:04 AM »
Im trying to make a match puzzle, something similiar to Bejeweled. After every turn i want to check through all tiles in the grid for chains. So i check the first tile and with a raycast check if the neighbour tile is the same colour, the loop repeats that for all the tiles, if a ray doesnt hit it goes to the next row (currently only check horizontal). when all checked it should delete the tiles of which the chain is long enough and then i would need another loop that check which tiles will have to move down to fill the empty space.

Is it normal that loops can only for loop a specific amount of cycles or time in playmaker? Im new to playmaker but have lots of experience with visual scripting through UDK Kismet.


kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #5 on: June 20, 2012, 09:14:33 AM »
well, there's always the infinite loop threshold in the playmaker settings... though it's better left unchanged in every normal scenario. Else you may just loose a lot of work if you encounter a real infinite loop.
Either way, if you somehow reached that infinite loop threshold, it might be better to actually recreate the entire fsm in a simpler manner, as 1000 calls (or whatever the defaul threshold is) might be a bit too much for some devices to process within a single frame or two. t'lags...
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #6 on: June 20, 2012, 09:21:24 AM »
Hi,

 ok. Not trying to get away from your problem, but I think you could use a more abstract representation of your board and tiles so that it is easier for you to work with.

 For example, if you maintain a 2 dimensional array, and in there store colors or tags for what's currently there. This will have many many benefits. you store the current board layout conveniently, and querying, working with ti will be easier too.

 Have you checked ArrayMaker, this is a solution I wrote specifically for playmaker to work with array, it has everything you need, and actions to loop through array items.

https://hutonggames.fogbugz.com/default.asp?W715
http://hutonggames.com/playmakerforum/index.php?topic=835.msg6941#msg6941


Now for your case, I think it's simply a problem of setup. For example, do you have by any chance all your tiles parented to the same object? If so, there is an action that loop through all childs of a gameObject, then you avoid the inifinite loop issue and you can then for chil, raycast it and do what every you need.
http://hutonggames.com/playmakerforum/index.php?topic=1088.0

Give this a try, if that still doesn't work, just shout :)


 Bye,

 Jean

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #7 on: June 20, 2012, 12:05:24 PM »
I got that problem more or les solved now but hit already the next wall. I have that with the raycast loop now with a send event that has a 0.01 delay, that is kinda instant, strangely its faster then a "wait".

My current Problem: Im using "get next child" to rename the objects of a match chain that is long enough. After all objects have been checked for chains, all those renamed objects get then again cycled through with "get next child" and "check name". But when i try to "delete" or "set parent" the current "get next child" it messes up the "get next child" function which results that not all objects get destroyed. There is always 1 or 2 that i cant receive anymore with "get next child". When i replace the "destroy" with a "scale" it cycles through all just fine.
But i just had the idea i could transform every object that should be destroyed to a certain position and then cycle through all these objects again with a raycast loop and destroy them with that. Will be kinda strange but should work.

@ kiriri
That infinite loop setting is already set to 100, dont know why it then stops my build with a warning where i have les then 100 objects. A lag shouldnt be a problem in my case since its turnbased and the loop only happens after a turn.

@ jeanfabre
More abstract would be nice but i need to check chains horizontal and vertical, "get next child" can then not replace the raycast check for neighbours (a object can also be in a vertical chain and at the same time in a horizontal) . Im already using tags for the colors check. Array Maker sounds great, i guess it would be then something similiar like objectslists in UDK kismet. I guess i could just use a array list to delete the objects.

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #8 on: June 20, 2012, 01:02:29 PM »
Just got my new problem solved with the ArrayMaker, thx! But i found it strange that the "array list count" gives me a count that is 1 too high. So before the "array list get" i had to make the index -1.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #9 on: June 20, 2012, 10:28:47 PM »
Hi,

 The eternal problem of where the index starts for an array... It's not a bug, it's the way it works with the api, so I sticked with it for the sake of accuracy.

 0 is your first item, so if you have 10 items, getting the last item will require you to get the item at index 9

 I could make an option to uncheck zero based indexing actually. I appreciate that for artists and beginners this is always the first hurdle with arrays... And since the community is largely composed of artists, it would make sense to implement that kind of goodies to avoid headaches...

Would you enjoy this change? or can you swing with it as is knowing now how it works under the hood?


 Bye,

 Jean

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #10 on: June 21, 2012, 08:34:26 AM »
Change wouldnt help me anymore now that i know it. :P Took me some time to figure it out, the errors where also only more confuseing for me. A comment or checkbox should be nice so new users can figure it out right away.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: raycast, getting error because of infinite loop that doesnt exist
« Reply #11 on: June 21, 2012, 11:19:03 AM »
Hi,

 Yes, I anyway decided that the next iteration of arrayMaker will have this ability and by default have it on, as well as clearly referenced in the actions to avoid confusion when you start learning all this, and anyway even me sometimes do build wrappers around my functions so that I do not use zero based indexing. It's like in some countries the first floor is the ground floor, I am always so confused with that! :)

Bye,

 Jean