pos problem

About advanced scenes, and the Thyme scripting language used in Algodoo.

pos problem

Postby Xray » Tue Dec 04, 2012 7:41 am

I am working on a bowling game, and when I place the pins in their initial positions, I want them to stay put until they get hit by the ball. At this point in development, I have good results by placing curly brackets around the pos value. For example: pos = {[0.544,2.8804]}. I have to manually place those curly brackets around the pos value because I am not able to do it with script. In other words, if I maintain the initial position in a local variable _pos, and if the value is, say [0.54,2.88], I want to be able to reset the pin position, after the pin gets knocked down, with pos = _pos and INCLUDE the curley brackets around the value. But it does not work with pos = {_pos}. The result is {_pos}, which will not work for my purpose. Could someone please tell me how to force curley brackets around the pos value in a script? I tried many ways without success.

Thanks
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: pos problem

Postby monstertje3 » Tue Dec 04, 2012 8:25 am

i don't know about your scripting problem with pos, but you could try to spawn in some hinges with a low breaklimit.
Basically, there are only 10 types of people in the world. Those who know binary, and those who don't.
Light travels faster than sound. That's why some people appear bright until they open their mouths.
User avatar
monstertje3
 
Posts: 343
Joined: Sat Sep 05, 2009 4:29 pm
Location: N-H, NL

Re: pos problem

Postby Xray » Tue Dec 04, 2012 8:32 am

monstertje3 wrote:i don't know about your scripting problem with pos, but you could try to spawn in some hinges with a low breaklimit.


That's a great idea! I'll consider doing that if my current method doesn't work out. THANKS A LOT!!! :clap:

EDIT: -- Well, I ended up putting script into each of the ten pins that forces them to translate back to their initial positions, and I did it with this script: pos = {[xvalue,yvalue]}. The "xvalue" and "yvalue" shown here are floating point numbers in my actual script for each pin. So, my problem has been solved for this particular scene, BUT I still want to find out if it's possible to get the same result when the X and Y values are saved in a variable. That is, I want to be able to store the values into pos from my local variable named _pos and also have curly brackets around the pos values. If this is possible please tell me how it can be done because it will be useful in other scenes that I create.
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: pos problem

Postby VZstrikez08 » Fri Nov 08, 2013 2:28 am

Couldn't you just set it so as the ball collides,the pins have X amount of time to lie there and then reset by using if so that when the time runs out the variable is reset to a specific value?
VZstrikez08
 
Posts: 6
Joined: Fri Nov 08, 2013 1:39 am

Re: pos problem

Postby electronicboy » Fri Nov 08, 2013 5:03 am

Xray wrote:But it does not work with pos = {_pos}. The result is {_pos}, which will not work for my purpose.

Basically, what's happening is, algodoo is seeing {_pos} as being a pure string, and not seeing the variable you've wrapped with {}!

so, lets use the good old string concatenation! Such a handy little bugger!

Code: Select all
pos = "{" + _pos + "}"


running that code will read _pos as a string, and add the {} around the string!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: pos problem

Postby Xray » Fri Nov 08, 2013 9:00 am

electronicboy -- I tried your script in the onCollide of a circle, and it doesn't work. Did you actually try it yourself in a scene?

EDIT - After playing around with it, I realized that in order to use text in a numeric value, you need to use "eval" to evaluate the text string. So I added eval to your script, and now it works. Here is what I ended up with:
Code: Select all
pos = eval("{" + _pos + "}")


Thanks for your help!
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: pos problem

Postby electronicboy » Fri Nov 08, 2013 4:07 pm

I didn't try the code, as I've used that before many times, with an assortment of both floats and strings, weird.
I wonder why that didn't work with an array, it does return a string value when you poll it... Oh well.

Glad you figured it out though!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: pos problem

Postby Xray » Fri Nov 08, 2013 6:28 pm

electronicboy wrote:I wonder why that didn't work with an array, it does return a string value when you poll it...


I believe the reason why it did not work without eval is because the position array (pos) cannot have a text string in its x and y values. It needs floating point numbers, but your script produces a text string. eval converts the text string into floating point values that pos can handle. That's my guess at what's going on.
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests