Physics simulator: Global variable storage?

I don’t have any better solution for you. If it works for you great! But it wasn’t intended to work that way. andnbsp;:)


do I understand the question yet? andnbsp;Global variables go at the top of the script. andnbsp;I’ve not done animation scripts but I assume it’s the same. andnbsp;I also define classes at top of script can’t remember if you have to. andnbsp;Here’s an example from the top of one of mine: In this Scene, Face and S can be accessed from anywhere. andnbsp;Is that what you want?


Option Explicit andnbsp; andnbsp;
Class SwarmClass
andnbsp; andnbsp;Public andnbsp; andnbsp;SwarmRadius andnbsp; andnbsp; andnbsp; ‘The radius
andnbsp; andnbsp;Public andnbsp; andnbsp;NumParticles andnbsp; andnbsp;
End Class
‘Declare global variables
andnbsp; andnbsp;Public andnbsp; andnbsp;Scene
andnbsp; andnbsp;Public andnbsp; andnbsp;Face andnbsp;
andnbsp; andnbsp;Const andnbsp; andnbsp; Pi= 3.14159265358979 andnbsp;
andnbsp; andnbsp;Public andnbsp; andnbsp;S ‘as SwarmClass andnbsp; andnbsp;

Sub Main (3DCApp)

That might be a good idea… I’ll give it a try.

Basically, what I want to do is get the user to select an object to animate. Then, the user is able to select various other objects for collision detection purposes. Finally, they enter initial trajectory and coefficients (restitution, static/dynamic friction, etc.).

When the AnimateObject call is made during animation, these parameters need to be called upon. Using a text file for the parameterized data sounds like a good idea.



if you haven’t used them in VBScript before, the code you need is in the scripts I posted last week for snap-to. andnbsp;Just remember the speed of light is constant.


George — thanks for the pointers… I am now using file I/O for the parameters, which is better.

[b:uq4lymyc]However[/b:uq4lymyc], in some circumstances it would be nice to generate global variables that have scope [u:uq4lymyc]that spans between[/u:uq4lymyc] objects.

It appears that all variables that are defined in a [i:uq4lymyc]component script[/i:uq4lymyc] only have scope that is defined to the object that contains the script.

How can one create truly global variables besides file I/O?

One of the reasons for this need is to accomplish more complex tasks that require dynamic computation across many objects, rather than simple parameterization. For example, collision detection between many objects or andquot;swarmandquot; behavior would be much easier if there was some way to share variables between objects.

Any ideas?


Not quite sure what you’re asking, so I’ll answer anyway <!– s:-) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":-)" title="Smile" /><!– s:-) –>

Could you do it by putting the variables in a text file and reading them from the script.

I’ve just started doing something similar for … well see my post on a script to snap-to. andnbsp;I write the coordinate info to a file with one script, and read it with another.


I am writing a physics simulator for 3DC, and so far it is working really well (objects bounce off ground with gravity and trajectories, etc.). 8)

However, I wonder if there is a way to set some global variables in an interactive script (ie. from Tools -] Run Script -] …) that can be later retrieved from a andquot;Component [animation] scriptandquot;. Currently, the component’s animation script has to have all parameters hard-coded, whereas I would like to assign some custom parameters to an object or group that persist and can be retrieved by AnimateObject() calls.

Any help would be greatly appreciated,

Thank you very much for your help, George —

Assume that you wrote the SwarmClass and placed the code in ObjectA’s component script. Are you saying that the class instantiation (S) will be visible to ObjectB’s component script?

If there is visibility between component scripts, then that’s great. I had assumed that there wasn’t visibility because I tried to define the same named global variables in two component scripts (but did not use the andquot;publicandquot; keyword) and there was no conflict in the assignments, which led me to believe a global in a component script only has scope local to that component script.

Thanks for any help — I have moderate experience with C++, but only started Visual Basic a couple days ago, so I need to learn a lot <!– s:) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!– s:) –> I am happy to see the support for scripting in 3DC as it really helps open up some functionality.


ohhh finally I geddit. andnbsp;Do you want to have two bouncy balls and say andquot;for this animation Gravity is 200m/s/sandquot; and just set gravity once for all bouncy balls?

Problem is I have no experience with component scripting for animation. andnbsp;But I find it unlikely that you are able to do what you want. andnbsp;Unless there is a heirarchy thing: is a group script executed before an object script, and can that object script refer to it’s group script? andnbsp;I doubt it.

I can think of ways to fudge it: using the text files for example. andnbsp;And a script can get certain properties for other objects – so you could for example make a andquot;ghostandquot; object whose only purpose is to allow you to use it’s coordinates as parameters for the scripts. andnbsp;Does that make sense.? andnbsp;

Can’t help you otherwise.

Yes…. that’s pretty much what I want. I was hoping that there would be some sort of hierarchical scope in scripting.

I have just confirmed that one cannot do this. The scope of a global variable is tied to the Component or Group script in which it is defined. Even though the Group script is run just before the component script, the globals aren’t available.

Text files won’t work when one is dynamically calculating data that needs to be passed between objects. And yes, it is possible to traverse a scene to enact the changes, but this is really too clumsy.

The idea of a ghost object is interesting, but what would be really nice is either:
[UL TYPE=SQUARE][LI]global script that can contain variables/classes which are accessible from all other component/group scripts[LI]custom data fields for an object[/UL]


I would go back to the text file idea. andnbsp;Where one or more files keeps the values of your globals. andnbsp;You write a sub that is included in each script so that:

ChangeGlobal (varname, ValueToBeSet)

does the work in each component script.. andnbsp;I just thought you might be able to use the clipboard, but a quick search suggests vbscript has no clipboard object. andnbsp;Javascript might be able to do it, but I’ve had no luck writing javasript for 3DC.

I don’t believe you can interact with object in a script. andnbsp;you can a bit with a plugin, but they don’t do animation ha ha


Geo —

[BLOCKQUOTE class=’ip-ubbcode-quote’][font size=’-1′]quote:[/font][HR]I would go back to the text file idea. andnbsp;Where one or more files keeps the values of your globals. andnbsp;You write a sub that is included in each script so that:

ChangeGlobal (varname, ValueToBeSet)

does the work in each component script..[HR][/BLOCKQUOTE]

Unfortunately this is probably too inefficient when one wants to share a lot of data between objects that is calculated on the fly and is recalculated often. Perhaps there might be an efficient way to code it so that the text I/O is kept limited…. hmm… I’ll give it some thought.

[BLOCKQUOTE class=’ip-ubbcode-quote’][font size=’-1′]quote:[/font][HR]I don’t believe you can interact with object in a script. andnbsp;you can a bit with a plugin, but they don’t do animation ha ha[HR][/BLOCKQUOTE]

That’s what I was afraid of andnbsp;:'(. I don’t have VBA, so I assume that I can’t write a plugin. This, combined with the fact that we can only select a single object means that making this script’s usage intuitive might be difficult to do <!– s:( –><img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad" /><!– s:( –>.

Thanks for all of the suggestions,

Aha… I’m happy to find out that I’m wrong <!– s;) –><img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink" /><!– s;) –>

[UL TYPE=SQUARE][LI]I don’t need VBA to write a plug-in, unless I want special dialog boxes, etc.

[LI]Most important of all — I got multiple-object selection working from within a script!!! ;D Entering a script does not prevent one from having interactive object/face selection! The [i:leh5qj92]only[/i:leh5qj92] problem I have is that the InputBox or MsgBox windows get put into the background once I reselect something in the perspective view, so I am forced to select the andquot;VBScriptandquot; task (in the bottom Windows toolbar) to resume my script. I can set the modality of the MsgBox windows, but this seems to only apply to the andquot;VBScriptandquot; task. Perhaps I’ll find a way to bring the MsgBox to the front periodically. Any ideas?

There’s an idea I hadn’t thought of… I imagine it would be a much slower access mechanism, but perhaps it may work. andnbsp;:-/

As for the simulator script, all I have left to do is perform some interactive object selection by the user in the script. I’m hoping that it’s possible to show the user a dialog box, then allow them to select an object/face, then continue with the script, etc. I don’t have access to 3DC right now, but I am very hopeful ??? that we can interactively allow selection during a script’s execution.


Well… it’s probably not designed for this purpose, but you could set a value in the registry as your andquot;globalandquot;. I’m not sure how to do this from a script though.


You must be logged in to reply in this thread.