pos problem
			8 posts			 • Page 1 of 1		
	
pos problem
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
			
		Thanks
- 
				

Xray - Posts: 501
 - Joined: Sun Jun 17, 2012 6:12 am
 - Location: USA
 
Re: pos problem
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.
		Light travels faster than sound. That's why some people appear bright until they open their mouths.
- 
				

monstertje3 - Posts: 343
 - Joined: Sat Sep 05, 2009 4:29 pm
 - Location: N-H, NL
 
Re: pos problem
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!!!
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.
- 
				

Xray - Posts: 501
 - Joined: Sun Jun 17, 2012 6:12 am
 - Location: USA
 
Re: pos problem
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
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
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:
Thanks for your help!
			
		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!
- 
				

Xray - Posts: 501
 - Joined: Sun Jun 17, 2012 6:12 am
 - Location: USA
 
Re: pos problem
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!
			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
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.
- 
				

Xray - Posts: 501
 - Joined: Sun Jun 17, 2012 6:12 am
 - Location: USA
 
			8 posts			 • Page 1 of 1		
	Who is online
Users browsing this forum: No registered users and 5 guests



