How to automatically refresh scripts in world editor?
by Alessandro · in Torque 3D Professional · 08/30/2011 (10:22 am) · 9 replies
Hello,
I was so impressed from the trial version that I just bought the full version! So here I am in the community!
1) One question: when do I need to post in public forum and when I need to post in private forum?
2) I'm a programmer, so I'm making some tests using scripting. My main issue is World Editor does not recognize modified scripts. For some scripts I need to use "exec()" to reload my functions, but in other cases (I'm studying and testing key binding for player control) it seems that exec() does not work at all.
I'm modifying: scripts/client/default.bind.cs
And I created a new file to test how to create objects at runtime: scripts/client/xaCreateObjects.cs
(but maybe I will put object creation in "server" directory I think).
Please can you give me more info how to work with scripts (documents seems not so exhaustive, even for new comers :-)
Thank you for your help!
I was so impressed from the trial version that I just bought the full version! So here I am in the community!
1) One question: when do I need to post in public forum and when I need to post in private forum?
2) I'm a programmer, so I'm making some tests using scripting. My main issue is World Editor does not recognize modified scripts. For some scripts I need to use "exec()" to reload my functions, but in other cases (I'm studying and testing key binding for player control) it seems that exec() does not work at all.
I'm modifying: scripts/client/default.bind.cs
And I created a new file to test how to create objects at runtime: scripts/client/xaCreateObjects.cs
(but maybe I will put object creation in "server" directory I think).
Please can you give me more info how to work with scripts (documents seems not so exhaustive, even for new comers :-)
Thank you for your help!
#2
I'm already using exec() but it seems has no effect for default.bind.cs.
So I made the binds and I reload an external script.
One question more:
I'm dynamically creating some cubes using this script:
Everything works well (I'm very happy about this!), but it seems the objects created using that script cannot be deleted inside the editor (it's funny, since I can select them and move, but they do not appear in the Scene tree (object editor).
08/30/2011 (11:15 am)
Thank you for your quick feedback.I'm already using exec() but it seems has no effect for default.bind.cs.
So I made the binds and I reload an external script.
One question more:
I'm dynamically creating some cubes using this script:
function xaCreateObject(%valore) {
if(%valore) {
for(%z=0; %z<30; %z+=3) {
for(%y=0; %y<30; %y+=3) {
for(%x=0; %x<30; %x+=3) {
%myPos = %x @ " " @ %y @ " " @ %z;
new TSStatic() {
internalName = "myCube" @ %x;
shapeName = "art/shapes/cube/cube.dae";
playAmbient = "1";
meshCulling = "0";
originSort = "0";
collisionType = "Collision Mesh";
decalType = "Collision Mesh";
allowPlayerStep = "1";
renderNormals = "0";
forceDetail = "-1";
position = %myPos;
rotation = "1 0 0 0";
scale = "1 1 1";
canSave = "0";
canSaveDynamicFields = "0";
};
}
}
}
}
echo("New Objects were created!");
}Everything works well (I'm very happy about this!), but it seems the objects created using that script cannot be deleted inside the editor (it's funny, since I can select them and move, but they do not appear in the Scene tree (object editor).
#3
Every time you change default.bind.cs you must delete config.cs before your changes take effect.
Also, I don't think dynamically created objects will show up in your Scene Tree. The Scene Tree shows objects that are part of the initial mission state but I think you will have to do some fiddling to get dynamically created objects in there. I believe it is possible, but I'm not sure how the tools scripts manage that list. Perhaps you can script it to write itself to the mission file directly - but that's probably a bad idea.
Oh, and welcome aboard!
08/30/2011 (11:37 am)
default.bind.cs is unique - I think you'll need to delete config.cs before exec-ing your new default.bind.cs since the engine will look for config before default.Every time you change default.bind.cs you must delete config.cs before your changes take effect.
Also, I don't think dynamically created objects will show up in your Scene Tree. The Scene Tree shows objects that are part of the initial mission state but I think you will have to do some fiddling to get dynamically created objects in there. I believe it is possible, but I'm not sure how the tools scripts manage that list. Perhaps you can script it to write itself to the mission file directly - but that's probably a bad idea.
Oh, and welcome aboard!
#4
So modify the code above to be:
08/30/2011 (12:55 pm)
Any objects you create that you want to save (or show up in the Scene Tree) need to be added to the MissionGroup SimGroup, like so: MissionGroup.add(yourObjectId);So modify the code above to be:
function xaCreateObject(%valore) {
if(%valore) {
for(%z=0; %z<30; %z+=3) {
for(%y=0; %y<30; %y+=3) {
for(%x=0; %x<30; %x+=3) {
%myPos = %x @ " " @ %y @ " " @ %z;
%obj = new TSStatic() { // MODIFIED LINE
internalName = "myCube" @ %x;
shapeName = "art/shapes/cube/cube.dae";
playAmbient = "1";
meshCulling = "0";
originSort = "0";
collisionType = "Collision Mesh";
decalType = "Collision Mesh";
allowPlayerStep = "1";
renderNormals = "0";
forceDetail = "-1";
position = %myPos;
rotation = "1 0 0 0";
scale = "1 1 1";
canSave = "0";
canSaveDynamicFields = "0";
};
MissionGroup.add(%obj); // NEW LINE
}
}
}
}
echo("New Objects were created!");
}
#5
08/30/2011 (1:44 pm)
Thanks Chris! I figured it was possible, just haven't had a need and never gave it any thought. Awesome!
#7
I noticed that, when I create the objects at runtime, they appear one after another one (like if the engine create them in multitasking, like if, from an object creation and the next one, the engine draws the scenery (refresh)). This process creation is really slow to create a lot of objects.
Is there any way to quickly create them in a single frame?
Thank you! :-)
08/30/2011 (2:10 pm)
Ehm... sorry, another question ( :-) )I noticed that, when I create the objects at runtime, they appear one after another one (like if the engine create them in multitasking, like if, from an object creation and the next one, the engine draws the scenery (refresh)). This process creation is really slow to create a lot of objects.
Is there any way to quickly create them in a single frame?
Thank you! :-)
#8
So, let's say that $pref::Net::PacketSize is set to 200 (bytes) and $pref::Net::PacketRateToClient is set to 10 (times per second). If ghosting data for 10 TSStatics fills up a single packet, the server will need to send 10 packets in order to ghost all of the TSStatics you're creating. On the client, this will cause 10 TSStatics to 'appear' at a time, every 100 milliseconds, until all 1000 are visible (which will take 1 full second).
If you're playing a singleplayer game (or on a local connection) Torque3D automatically forces $pref::Net::PacketRateToClient to be 128 and $pref::Net::PacketSize to 1024.
Now, solutions:
* Depending on whether your game is multiplayer or singleplayer, you can either increase the $pref::Net::PacketSize and $pref::Net::PacketRateToClient or modify NetConnection::checkMaxRate() in the source code.
* You can also (possibly) change -when- you're calling your TSStatic creation code. Check core/scripts/server/missionDownload.cs and you'll see that mission data is sent to clients in 'phases'. If you call your creation code in one of the early phases (probably at the end of StartPhase2Ack) you might be able to send all of your TSStatics to the client before they actually render anything, effectively hiding the ghosting time.
08/30/2011 (9:05 pm)
The 'staggered' creation effect you're seeing is caused by the engine ghosting the objects to your client. In the code above, you're creating 1000 TSStatics. Each of these, once created, has certain information that needs to be passed on (by the server) to any client. Things like position, rotation, scale, etc. all need to be sent out. There's a limit on how much data the server can send in a single packet (and that limit is set to whatever $pref::Net::PacketSize is). The server sends these packets $pref::Net::PacketRateToClient times per second. So, let's say that $pref::Net::PacketSize is set to 200 (bytes) and $pref::Net::PacketRateToClient is set to 10 (times per second). If ghosting data for 10 TSStatics fills up a single packet, the server will need to send 10 packets in order to ghost all of the TSStatics you're creating. On the client, this will cause 10 TSStatics to 'appear' at a time, every 100 milliseconds, until all 1000 are visible (which will take 1 full second).
If you're playing a singleplayer game (or on a local connection) Torque3D automatically forces $pref::Net::PacketRateToClient to be 128 and $pref::Net::PacketSize to 1024.
Now, solutions:
* Depending on whether your game is multiplayer or singleplayer, you can either increase the $pref::Net::PacketSize and $pref::Net::PacketRateToClient or modify NetConnection::checkMaxRate() in the source code.
* You can also (possibly) change -when- you're calling your TSStatic creation code. Check core/scripts/server/missionDownload.cs and you'll see that mission data is sent to clients in 'phases'. If you call your creation code in one of the early phases (probably at the end of StartPhase2Ack) you might be able to send all of your TSStatics to the client before they actually render anything, effectively hiding the ghosting time.
Torque Owner Nathan Martin
TRON 2001 Network
in order to reload your modified script. Note that there are times when you will need to restart the entire game program in order to see the changes.