Using Torque Script at run-time by avoiding compiling?
by Ahmed@ · in Torque Game Engine · 11/19/2004 (2:23 am) · 17 replies
Hi,
I'm new to Torque and i wonder if it is possible to use Torque script at run-time without compliling them into byte-code first.. So far i only saw one game engine which allows you to do that 'Panda3D' however i'm not overlly impressed with thier engine.
Basically what i'm trying to do is to have a god father controller in the environment which can use the script freely at run time to change any aspect of the game the script has access to.
Thanks
I'm new to Torque and i wonder if it is possible to use Torque script at run-time without compliling them into byte-code first.. So far i only saw one game engine which allows you to do that 'Panda3D' however i'm not overlly impressed with thier engine.
Basically what i'm trying to do is to have a god father controller in the environment which can use the script freely at run time to change any aspect of the game the script has access to.
Thanks
#2
11/19/2004 (3:31 am)
Then is it possible to somehow alter parameters dynamically during gameplay? for instance could you alter how high your player can jump during the game using the console or a scripted function?
#3
Yes, it is possible, you need to alt-tab out, edit the attribute you want in the .cs file and reload the .cs file and datablocks to all players. Or at least, that worked in Tribes 2, I don't have the exact function handy but I'll find it when I get back to my apartment and stick it up here for you.
11/19/2004 (4:00 am)
Tahitian,Yes, it is possible, you need to alt-tab out, edit the attribute you want in the .cs file and reload the .cs file and datablocks to all players. Or at least, that worked in Tribes 2, I don't have the exact function handy but I'll find it when I get back to my apartment and stick it up here for you.
#4
(a) Not what he wants to do and
(b) wrong.
Tahitian, yes you can do that. It's slightly tricky, and will involve editing player.cc to expose the jumpForce variable to script and get Player::updateMove to use a member rather than the datablock variable.
Ian
11/19/2004 (4:03 am)
Jeff, that's(a) Not what he wants to do and
(b) wrong.
Tahitian, yes you can do that. It's slightly tricky, and will involve editing player.cc to expose the jumpForce variable to script and get Player::updateMove to use a member rather than the datablock variable.
Ian
#5
Or maybe interface with the console itself?
11/19/2004 (4:28 am)
Is there any other way to achieve this other than the console, say can i create my own console because i want to be able to link it to an external program for example my own ai engine, etc. Or maybe interface with the console itself?
#6
Why would you want to do it another way? Anyway.. I don't see the problem here..
Just load the file, it will be compiled (that doesn't take more than a few milliseconds) and then you can use it. Change something in the original .cs file and reload it.. again, it will be compiled and you can use the new file.
If that's a problem, you can rather easily (if you know what you're doing) make it load uncompiled data instead, and pass the compiler.
11/19/2004 (4:45 am)
Portalguy,Why would you want to do it another way? Anyway.. I don't see the problem here..
Just load the file, it will be compiled (that doesn't take more than a few milliseconds) and then you can use it. Change something in the original .cs file and reload it.. again, it will be compiled and you can use the new file.
If that's a problem, you can rather easily (if you know what you're doing) make it load uncompiled data instead, and pass the compiler.
#7
For example building a vocabulary game for kids which is going to be linked to a dictionary, theasures, sounds, etc.
So by clicking on an object in the world it will ask the dictionary for a definition and theasures for other things, and maybe play sound etc.
This to mention few things..i also want the teacher to be able to monitor the world and answer the user clicks on objects.
11/19/2004 (4:58 am)
The reason for wanting another way is that i want to interface it with an external program which is going to monitor some objects and issue commands (scripts).For example building a vocabulary game for kids which is going to be linked to a dictionary, theasures, sounds, etc.
So by clicking on an object in the world it will ask the dictionary for a definition and theasures for other things, and maybe play sound etc.
This to mention few things..i also want the teacher to be able to monitor the world and answer the user clicks on objects.
#8
Just use the .cs files instead of the .dso's. They are linked to eachother anyway. Maybe I misunderstood your intentions, sorry if so.. but I really believe you've got this compilation thing on the wrong end :)
You know, you can always read the files.. just not the dso's, which are the same as the .cs/.gui files anyway, as long as you always compile them when they are changed.
Edit: Grammar.
11/19/2004 (5:01 am)
As I said, you can do that with the stock compilation scheme.Just use the .cs files instead of the .dso's. They are linked to eachother anyway. Maybe I misunderstood your intentions, sorry if so.. but I really believe you've got this compilation thing on the wrong end :)
You know, you can always read the files.. just not the dso's, which are the same as the .cs/.gui files anyway, as long as you always compile them when they are changed.
Edit: Grammar.
#9
In steps:
1- (to get the object status) create .cs file to query the object status and load it.
2- (pass this to an external program) the program which initiated the creation and loading the .cs file (in step 1) will pass the result to the external program
3- (pass the results from the externa program back) get the results from the external program and create .cs file for the action you want to occur and load it.
Please let me know if i'm still on the wrong track
thanks
11/19/2004 (5:15 am)
Ok let me see if i understood this correctly... .cs files can be loaded and executed at run time..so if i wanted to query the status of an object in the world i'll have to create .cs file at run time and load it and that will give me the status. The next step is to pass this 'status' to my external program and get instructions on what to do to the object (playsound for example). The script to load sound will be put again in .cs file and load it.In steps:
1- (to get the object status) create .cs file to query the object status and load it.
2- (pass this to an external program) the program which initiated the creation and loading the .cs file (in step 1) will pass the result to the external program
3- (pass the results from the externa program back) get the results from the external program and create .cs file for the action you want to occur and load it.
Please let me know if i'm still on the wrong track
thanks
#10
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2475
11/19/2004 (5:16 am)
Are you trying to do an admin type thing? the link below may helpwww.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2475
#11
11/19/2004 (5:23 am)
The admin only controls the game world using script, but doesn't allow you to do what i want of linking and communicating with an external program
#12
IMO it would be much easier to create a new datablock with your new attributes set to it and then use %player.setDataBlock(%newBlock); instead of making a bunch of engine changes to alter one attribute or more. This is easily accomplished and pretty much just as effective.
If I'm following you correctly this would appear to be a great place for use of the HTTPobject class or a Telnet interface.
About that Admin mod. It looks like a great resource with a lot of good stuff in it, but just on a glanceover I noticed some pretty big flaws in it that should be corrected before use. This for example just jumped right out at me(I've commented to make the flaw easier to see).....
So using the resources own example you would call a plugin install like so...
AdminMenu.RegisterPlugin(ChangeMission_Admin);
Which should be just fine on the first run except for the fact that after it passes the first checks you create a new object named "ChangeMission_Admin_Object" and therefor when you try to run the same plugin again you'll soon see that ChangeMission_Admin != ChangeMission_Admin_Object and you will end up with two ChangeMission_Admin_objects in your system. Whats worse is when you call...
it will fail to find the proper plugin and remove it because it's looking for the wrong name. And the worst part is that even though your game is telling you that it can't find the plugin(does not exist), it will also tell you that it does exist when you call ...
Because the name change has been accomidated for at this location. If your not paying attention or not experienced enough to recognize this it could be quite frustrating to say the least.
And I hate to be so critical (just trying to be honest and helpful) but the mission change admin is a memory leaking disaster for the most part.
11/19/2004 (8:49 am)
@ IanQuote:Tahitian, yes you can do that. It's slightly tricky, and will involve editing player.cc to expose the jumpForce variable to script and get Player::updateMove to use a member rather than the datablock variable.
IMO it would be much easier to create a new datablock with your new attributes set to it and then use %player.setDataBlock(%newBlock); instead of making a bunch of engine changes to alter one attribute or more. This is easily accomplished and pretty much just as effective.
Quote:The admin only controls the game world using script, but doesn't allow you to do what i want of linking and communicating with an external program
If I'm following you correctly this would appear to be a great place for use of the HTTPobject class or a Telnet interface.
About that Admin mod. It looks like a great resource with a lot of good stuff in it, but just on a glanceover I noticed some pretty big flaws in it that should be corrected before use. This for example just jumped right out at me(I've commented to make the flaw easier to see).....
function AdminMenu::RegisterPlugin(%this, %plugin)
{
// Pretty standard here
if(%plugin $= "")
return;
// While this is a good idea, it's definately not going to work
if(isObject(%plugin))
{
error("Torque Plugin ",%plugin," previously loaded");
return;
}
// because right here you are changing the original name to something new.
%name = %plugin@"_Object";
%plugid = new ScriptObject(%name)
{
};So using the resources own example you would call a plugin install like so...
AdminMenu.RegisterPlugin(ChangeMission_Admin);
Which should be just fine on the first run except for the fact that after it passes the first checks you create a new object named "ChangeMission_Admin_Object" and therefor when you try to run the same plugin again you'll soon see that ChangeMission_Admin != ChangeMission_Admin_Object and you will end up with two ChangeMission_Admin_objects in your system. Whats worse is when you call...
function AdminMenu::RemovePlugin(%this, %plugin)
{
if(%plugin $= "")
return;
if(!isObject(%plugin))
{
error("Torque Plugin ",%plugin," does not exist");
return;
}it will fail to find the proper plugin and remove it because it's looking for the wrong name. And the worst part is that even though your game is telling you that it can't find the plugin(does not exist), it will also tell you that it does exist when you call ...
function AdminMenu::isRegisteredPlugin(%this, %plugin)
{
[b]%name = %plugin@"_Object";[/b]
for(%p=0; %p<%this.maxPlugin; %p++)
{
if(%this.pluginList[%p] $= %name)
{
return true;
}
}
return false;
}Because the name change has been accomidated for at this location. If your not paying attention or not experienced enough to recognize this it could be quite frustrating to say the least.
And I hate to be so critical (just trying to be honest and helpful) but the mission change admin is a memory leaking disaster for the most part.
#13
Edit: Nevermind. I didn't read all of it.
11/19/2004 (9:02 am)
Haven't noticed anything Gonzo.. are you sure?Edit: Nevermind. I didn't read all of it.
#14
11/19/2004 (9:34 am)
If you mean "Sure about the memory leak" then yes. Positive. I took another look to be sure, and I was mistaken in the severity of the leak. Although it's not as bad as I first thought when I glanced it over it is there. Assuming you had 10 missions in your mission folder, then I'm 99.99% sure if you were to fire up the admin and take a look at your tree you'll find TWENTY objects named "MissionInfo" just hanging out in your tree root. TGE has the same basic flaw in the StartMission aspect of the client. When the client create's a mission listing it will also leave a pack of MissionInfo's hanging out till the server is shutdown. At first i thought that the ChangeMission_Admin was doing those loops over and over which would have eventually left hundreds of MissionInfo's in your root, but I see after a second look that this is only execed one time as a startup routine and will only affect you once. Assuming you had 10 miisions in your server, and you launch as a client, you'll end up with 31 MissionInfo objects in your root at startup with 20 coming from the admin, 10 from your startMission gui and 1 from TGE building it's info to send to the clients. The code just needs a little attention to take care of these things. I rebuilt all that stuff in the SSP to eliminate those problems.
#15
02/26/2005 (1:25 pm)
After some time away from TGE now i'm back working with it again and i found a solution for my problem here and it is using the console evaluatef function this will load an arbitrary script code.
#16
Looking it further i found that it doesn't accept even "%x=1;" but it accepts "echo(2);".
Thanks
03/06/2005 (6:58 am)
I found out that evaluatef cann't handle code which has 'for' loop. Is there a way around this or another function which will handle these sort of statements without having to save a file and then call exec.Looking it further i found that it doesn't accept even "%x=1;" but it accepts "echo(2);".
Thanks
#17
03/06/2005 (7:10 am)
'evaluate' instead of 'evaluatef' did the magic for me.
Associate Ian Omroth Hardingham
Default Studio Name
Ian