Physion

  • Increase font size
  • Default font size
  • Decrease font size
Welcome, Guest
Username Password: Remember me

Scripting Examples
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Scripting Examples

Scripting Examples 6 years, 3 months ago #599

  • DonDon6
  • OFFLINE
  • Junior Boarder
  • Posts: 30
Is there a comprehensive manual or a sample list of scripting options in Physion.

For example, how to a set or adjust the various attributes of an item.

When I create an item can I also set various attritbures. HOW ?

DonDon6

Re: Scripting Examples 6 years, 3 months ago #600

  • Dimitris
  • OFFLINE
  • Administrator
  • Posts: 218
Hey Don,

Have you visited Physion's wiki? (wiki.physion.net)

In general, Physion's scripting allows you to do the following:

For example, how to a set or adjust the various attributes of an item.
When I create an item can I also set various attritbures. HOW ?
All items that you create (either using the graphical tools or by scripting) have a "Name" property whose value is assigned automatically. When you click on an item, the property editor shows item's properties. Most of those properties can be accessed using the following syntax:

<item_name>.<property_name>

For example if you have a circle whose Name property is "item4", writing "item4.Radius" in the console would yield its radius. In the same way you could set its radius by writing "item4.Radius = 5".

Note that most of the times an item is created in scripting like that:
var rectangle = world.createRectangle(...);
which means that you can also access this item's properties by its variable name (e.g. rectangle.Radius)
Last Edit: 6 years, 3 months ago by Dimitris.

Re: Scripting Examples 6 years, 3 months ago #601

Hi DonDon6. (EDIT: Just noticed Admin has since replied. Good!)
Admin (Dimitris) & Lynxx are very knowlegable in all things technical, but i will try to
explain a few things that i know, in the mean-time. Let me start with a bit of gen info...

I assume you are mainly talking of the Properties of objects, when referring to attributes.
So you know roughly what is going on in the background, here is what is taking place....

There is a set of system independent mathematics for 2D physics, called 'Box2D'.
This handles all the complicated maths that is needed to make things realistic.
Nokia have created a C++ Application Development Framework, that amongst many
other uses, is being used to handle the front-end manipulation of the whole system.
Dimitris has created Physion, using all that underlying stuff, for a visual front-end.
To simplify intervention by users like yourself, there is a 'Javascript-like' scripting
interface. It is basically Javascript, but includes many other application-specific
commands, making ref to the objects, their properties, and the graphics-world.

Physion is fairly new, and most of the help/info was scattered throughout this forum,
but now anything of tuition relevance is now in a 'wiki' site, indicated bellow....
wiki.physion.net/doku.php
Particularly, see Introduction to Scripting, Scripting Tutorials, & Scripting Reference.
For example, to create a circle with scripting, you could say....
var circle = world.createCircle(0.0, 8.0, 0.0, 2.0);
Meaning centre X,Y is 0,8 the rotational angle is 0, and the radius is 2.
You can then change any objects Properies, by using a full-stop in-between, like....
circle.Restitution = 0.5; or circle.ShowLine = false;
These properties are the same that you see in the Property-List, for an object.
Try to give objects meaningful names, instead of just 'item56', and 'item78'.

One of the best on-line refs i've found for Javascript, is....
developer.mozilla.org/en/JavaScript/Reference
It's very user friendly, and explains all language components well, with examples.

As you will see, in the 'Wiki' pages, there are many things you can do, with scripting,
other than what I have mentioned. For example, with scripting, you can destroy
(remove) an object from the scene. Say you had a circle called 'Ball1'.....
world.removePhysicsItem(Ball1); would delete it from existence !
The above example is from the page....
wiki.physion.net/doku.php?id=scripting:reference:physics_world

NOTE: To DonDon6....
I looked at your uploaded scene for a 'Pool-Table'. I noticed in the Script, that as the
balls were supposedly going down the holes, you just changed the Opacity to zero!
They are still on the table, and can be collided with. Use the code i showed above!

GENERAL NOTE:
When you create a circle, for example, like above, and then in the same block of code
refer to the properties, like circle.Restitution etc., that this only works until you
create another circle, as now the properties coded are for that one. Even though it
was called 'circle', it actually has a generic name now, like 'item23' or what ever.
So to ensure that you know what circle you are dealing with, unless it is not important,
like creating hundreds of balls that keep falling, then make the last thing you do with
a circle, (or what ever you are creating), is to give it a prper name. like....
var circle = world.createCircle(0.0, 8.0, 0.0, 2.0);
circle.Restitution = 0.5; etc. etc. then...
circle.Name = "BlueBall"; or what ever.

Hope some of this helps.
Read through the forum, and the Wiki pages, and download some of the sample
scenes, to see what has been done. Download some .script files and check them out.
Often objects are hidden behind others, so you may have to change the ZOrder.
1x1 square diag = root-2. Cube diag = root-3. Beautiful !
Last Edit: 6 years, 3 months ago by Glenn555.

Re: Scripting Examples 6 years, 3 months ago #602

  • DonDon6
  • OFFLINE
  • Junior Boarder
  • Posts: 30
Tanks for your response !

Updated PoolTable (ImprovedPoolTable) as you suggested.
However, it now crashed Phusion when I try to reset it - any thoughts.

Don

Re: Scripting Examples 6 years, 3 months ago #603

  • Lynxx
  • OFFLINE
  • Moderator
  • Java/C#-Developer
  • Posts: 223
DonDon6 wrote:
However, it now crashed Phusion when I try to reset it

Reset it, how ? The only code in ImprovedPoolTable is in OnContact of the "Cornerballs" ( world.removeBody(other); ).

After they balls have been removed they are not only removed from the view, they are completly gone, which means you have to create new balls.
Infinity is vast, especially near end.
bye, Lynxx

Re: Scripting Examples 6 years, 3 months ago #605

  • DonDon6
  • OFFLINE
  • Junior Boarder
  • Posts: 30
By restore I mean with the backup key.
The Improved Pool program works fine and can be stored up until one of the balls is erased. Then if I attempt a store it says "Physon Has Encoultered and Error and must Shut Down" and closes.

I just thought I might have made some type of error in the code. Perhaps when an item is removed the physical item pointers get messed up.

Don
  • Page:
  • 1
  • 2
Moderators: Lynxx, Glenn555
Time to create page: 0.15 seconds