What's up with this-part II?

Thanks to all who take the time to help. I’m stumped on this one. I’m desperately trying to get the computer to check for matches (3 in a row, 4 in a row, etc.) on my puzzle board.

Here’s the setup- computer randomly fills a 10x10 grid with 7 different types of pieces, starting at 0,0,0 going to 9,9,0. I have a ray sensor that starts at 0,0,0 attached to an empty (is this the problem?). I know the empty travels all 100 positions, because it prints 0,0 all the way to 9,9, but my ray sensor never comes back positive. Its looking for objects with the property piece (string property named “piece” on all). Its on true level triggering, with a far enough range, no delay in logic tics, and +Z axis. One other detail is that, its doing all this in one frame of the game (which eventually I’d like to change anyway, but one thing at a time). Also, this is in the same script that fills the board (don’t think that makes a difference). So, in case I’m not clear, why won’t my ray sensor hit any of my pieces???

thanks again,
guruhunt

P.S. sorry for the “piece” overload!!! Peace out!!!

Now that,… was confusing. =]

Are your ‘pieces’ set to actor?

Can you post a .blend?

Cheers!

Yer not do that. Yer make peices set variables.

Posting the Blend is another story on my 33k dail-up connection :(, No they were not set to actors, but that wasn’t it. Also set bounds, that didn’t help.

As simple as I can put it…(lol)…100 objects on a 10 x 10 grid. A ray sensor travels the grid one square at a time. If raysensor.isPositive(): never comes back true. Its looking for a property named “piece”. All 100 objects have that property (a string property named piece). Why won’t the ray sensor find any objects??

thanks,
guruhunt

Can you please explain in more detail how the pieces get placed. I understand they are randomly placed but did you use python or logic to do this?

If you did python can you paste in the code you used, we can then figure a way to record how they were placed and then work on how to find if they next to another of the same type of piece.

Sorry, it posts my messages halfway through sometimes, continue below.

I used python to place the puzzle pieces at 0x0, 0x1, 0x2 etc., randomly choosing between the 7 types. I don’t really want to track the pieces while placing them, because of future concerns. It seems easier (at this point) (hah) to just shoot a ray at 0x0 then move to 0x1 shoot the ray and compare the two, so on and so forth. The computer places the pieces at 0x0, 0x1, 0x2, etc. and the computer also places the ray at 0x0, 0x1, 0x2, etc, so why won’t it getHitObject(). That’s the bottom line question right now…Why does

if raysensor.isPositive():
…pieceimchecking = raysensor.getHitObject()…#(won’t put spaces at the beginning of the line)
…piecename = pieceimchecking.getName()
print piecename

print nothing? As far as I can tell raysensor is never positive. I have added a print x,y line in there, so I know the raysensor goes from 0x0 to 9x9, with a blank line in between each one. Thanks so much for your input :slight_smile:

Ok, its good that you used python because you can figure out what object gets placed where.

I’m assuming you’re using randint() for you randomness and then some if conditions to decide what piece gets placed, lets say you call the piece to be placed “piece”. When that piece gets placed you may be doing something like this:

add.setObject(piece)
GameLogic.addActiveActuator(add, 1)

add is an add object actuator. the add object actuator has a function called getLastCreatedObject(), we are going to use this so another line of code:

added_piece = add.getLastCreatedObject()

We can now use the exec function to create a variable from string, the variable will be piece_xy where x and y are the co-ordinates of the piece, so add this to our building code:

x = own.getPosition()[0]
y = own.getPosition()[1]

exec("piece_" + str(int(x)) + str(int(y)) + " = added_piece")

I also used the str() function (converting ints and floats to string) and the int() function (converting floats to ints)

So now instead of trying to find out what piece is at the co-ordinates (4,3) you can just go “piece_43.getName()”

I hope this helps you and if you need help changing your blend to work with this instead of the ray sensors I can help you out.

Sounds like this would help, but I’m confused? Can you explain the exec function a little more. (I need a python book) I’m creating a variable named piece_xy for each piece. How exaclty will I recall that… Man this is it. Almost there, now I’m gonna get this thing working.

yes all assumptions correct, except I used actAddGuy.instantAddObject(). Thanks sooo much for your help!!!

I got it!!! I just figured it out!!! Thank you, thank you, thank you.

Glad that I could help.

Make sure your ray sensor extends far enough, or that it extends not TOO far (could possibly be) and make sure the empty is near enough to the pieces.