Combining two values

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

Combining two values

Postby Tronzoid » Mon Apr 30, 2018 9:57 pm

How would I combine the X and Y of a value into a single value?
Tronzoid
 
Posts: 11
Joined: Fri Oct 06, 2017 6:53 pm

Re: Combining two values

Postby Xray » Mon Apr 30, 2018 11:58 pm

Not sure what you mean by "combine X and Y of a value". If you are asking to combine X and Y values of a coordinate, then that does not make sense. Why would you want to do that? So, because your question doesn't make sense, please explain in detail what you are trying to do and then maybe I or someone else could help you.
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Combining two values

Postby Tronzoid » Wed May 02, 2018 5:58 pm

What I meant to say was I wanted to use an an equation to combine the xy coordinates of a value like vel into a single number, what would that equation be?
Tronzoid
 
Posts: 11
Joined: Fri Oct 06, 2017 6:53 pm

Re: Combining two values

Postby Xray » Wed May 02, 2018 6:24 pm

vel is an array which is made up of two elements, X and Y. You can add the X and Y values to form a single value like this: velXY = vel(0) + vel(1)

The values within the parentheses are indexes, where the first element of any array is index zero, and the second element is index one, etc. You can do exactly the same thing with the object's position: posXY = pos(0) + pos(1).

Hope this is what you wanted. :angel:
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Combining two values

Postby Tronzoid » Wed May 02, 2018 6:31 pm

Another question, how would I calculate the relative velocities of two objects colliding? I wish to write a script that reduces an objects value depending on the objects kinetic energy.
Tronzoid
 
Posts: 11
Joined: Fri Oct 06, 2017 6:53 pm

Re: Combining two values

Postby Xray » Wed May 02, 2018 7:12 pm

The magnitude of a vector (such as velocity) can be calculated like this: scene.my.vel1 = math.vec.len(vel) Using the velocity magnitude of each object, you should be able to calculate the hp during or just prior to a collision.

Look through the first couple of subject entries at the top of the Thyme scripting topic, and you will find some very helpful information there including equations and functions.
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Combining two values

Postby Tronzoid » Wed May 02, 2018 9:22 pm

How would you type something like ammo = 1 in an if then else array?
Tronzoid
 
Posts: 11
Joined: Fri Oct 06, 2017 6:53 pm

Re: Combining two values

Postby Xray » Wed May 02, 2018 10:29 pm

Your question is ambiguous, and so I need more details in order to answer it.

1. What is "ammo"? Does "ammo" contain the value that you want to test, or is "ammo" the result of the test? If the result, do you want it to be stored with a 1 if the test is true, or if the test is false?

2. I never heard of an "if then else array". You need to give more details so that I understand what you want.
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Combining two values

Postby Tronzoid » Wed May 02, 2018 10:40 pm

Naargh! I meant how would you type out value = 1 in the if section of the structure *facepalm*
ammo is the variable I am trying to get to work.
Tronzoid
 
Posts: 11
Joined: Fri Oct 06, 2017 6:53 pm

Re: Combining two values

Postby Xray » Wed May 02, 2018 10:59 pm

Naargh! Your question still doesn't make sense. *facepalm*

I don't know what you mean by "type out value = 1". If you are going to ask technical questions, you must ask them using the same kind of esoteric language that the instructor can understand. Apparently, you have little to no programming experience, and that's why I have trouble understanding you. Rather than trying to design and build a complex game, you really should start by learning the basics of Thyme scripting. You need to learn how to walk before you know how to run. I see that the user kilinich gave you the same advice in a different forum post. There are plenty of tutorials which can help you learn, but you must be willing to take the time to learn them before trying to tackle a complex game. There are people, such as kilinich and myself, on this forum who are wiling to help you and to answer your questions, but no one is going to spend many hours holding your hand by feeding you lots of scripts, equations, and algorithms. Now go learn the basics, then come back and ask proper questions. :roll:
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Combining two values

Postby FRA32 » Tue Jun 05, 2018 6:17 pm

val == number ? {do this} : {else do that}

You can replace == with any relational operator, so ==, >, <, >=, <=, != work as well. You can also chain multiple conditions by using && as "and" and || as "or"

example:

if pos(0)>2 && sim.time <= 10 ? {} : {};

in your case its ammo == 1 ? {} : {};
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest