Author Topic: Quite a few questions  (Read 1494 times)

I made a list in school of things I wanted to know about Torquescript. Please answer clearly, I'm not a pro scripter.
1. What are TCP objects? How do I use them? How are they useful?
2. How can I call a function client-sided when the client sends a servercmd?
3. What are script objects? How do I use them? How are they useful?
4. How do I get source code from a default function?
5. Is it possible to bring up a list of default global variables? How?
6. What is the most complex thing to learn in TS?
7. What is the correct way to call a parent function in a package?
8. How can I store variables for clients? (Player persistence?)
9. How can I force third person with a client-sided console command?

Thank you for your time!

3. What are script objects? How do I use them? How are they useful?
Script objects are extremely useful. They are TorqueScript's version of object oriented programming (google it).

4. How do I get source code from a default function?
You either ask someone who has decrypted the .dso files, or decrypt them yourself.

5. Is it possible to bring up a list of default global variables? How?
Put $ in console, press tab repetitively. Alternatively you could try exporting "$*", however recently that seems to be crashing for whatever reason.

7. What is the correct way to call a parent function in a package?
parent::FUNCTION(%ARG1, %ARG2, ... , %ARGN);
Make sure that you return that if the function you are packaging returns something. If in doubt, do it anyway.

8. How can I store variables for clients? (Player persistence?)
Use file objects to create a file that stores the data. Its a big subject, look them up.
« Last Edit: June 01, 2015, 05:57:23 PM by boodals 2 »

Answers limited to what I feel like looking up/typing on a phone

1. They let you send/receive TCP packets. There should be a decent guide on their use somewhere, or I can post an example when I get home

2. Not sure when you mean. Sounds like your looking for clientcmds?

3. They don't really have any default behavior. You can store data and give them a class name and right methods for that class

4. You don't. Either a, see if Badspot posted the source, b, keep an rtb 1.x copy and see if the functions are in there, or c, rewrite it.

5. export("$*","config/vars.cs");
Vars might be reversed, I'm not positive

6. The hardest thing to learn in any language is how to program. Once you've got that, learning anther language is just learning syntax, default functions, etc. Nothing really stands out to me as 'hard'

7. Parent::function name(args);

8. Look into the player persistence add-on?

9. Not sure. Try tracing, or reading your prefs file to see what function is called


1. TCP Objects are objects that allow you make a TCP connection to an arbitrary IP address to send and receive data. This is useful for downloading from webpages, making POST requests (It's an HTML thing) and saving binary files like zip files into the blockland folder.
2. If you mean to call a function on the clients side, you need to create a clientcmd on their client, which means you need to give them an addon.
3. Script objects are essentially just regular objects that you can assign properties, names and classes to to make coding in general easier and pseduo-object-oriented.
4. You can ask here and if someone has it they'll post it. Some functions you can't get the source code of because they're in the c++ code and exclusive to blockland, which means you'd have to go digging around in the exe to find it, which is very difficult.
5. You can look through the global variables by entering a partial name in the console and pressing the tab button to cycle through them.
6. Probably classes, how to properly TCPObjects or any number of other obscure classes and functions in the language.
7. If you mean how to properly parent a function, it differs from function to function. Some you need to return parent, some you dont need to return at all, some you need to call the parent to before your code executes then return the parent at the end, it depends on what you need to do.
8. Using the player persistence mod, I would guess. I'm sure there's some way to add variables onto it.
9. No idea.

9. How can I force third person with a client-sided console command?
What do you mean by "force"? This will make your player third person only:
ServerConnection.getControlObject().getDatablock().thirdPersonOnly = true;

2. How can I call a function client-sided when the client sends a servercmd?
I think what you're looking for is commandToServer

Code: [Select]
commandToServer('Self Delete');
commandToServer('messageSent', "Hello");


Oh oh! I know one of these!

8.

%file(s)!

obviously you would be defining variables



Code: [Select]

function serverCmdSave(%client)                //Manually save client's progress
{
        %file = new FileObject();
        %file.openForWrite("config/server/saving/"@%client.bl_id@".txt");
        %file.writeLine(getDateTime());
        %file.writeLine(%client.variable);
        %file.writeLine(%client.variable);
        %file.writeLine(%client.variable);
        %file.close();
        %file.delete();
        commandToClient(%client,'centerPrint',"<font:impact:24>\c3Saved game stats under BL_ID \c6"@%client.bl_id,3);
}
function serverCmdLoad(%client)                //Load the client's progress
{
        if(isFile("config/server/saving/"@%client.bl_id@".txt"))
        {
                if(%client.BS_loaded)
                {
                        commandToClient(%client,'centerPrint',"<font:impact:24>\c3You already loaded your stats for this session",3);
                        return;
                }
                %file = new FileObject();
                %file.openForRead("config/server/saving/"@%client.bl_id@".txt");
                %date = %file.readLine();
                %client.variable1 = %file.readLine();
                %client.variable2 = %file.readLine();
                %client.variable3 = %file.readLine();
                %file.close();
                %file.delete();
                commandToClient(%client,'centerPrint',"<font:impact:24>\c3Loaded game stats saved last on \c6"@%date,3);
        }
        else
        {
                commandToClient(%client,'centerPrint',"<font:impact:24>No save file found for you!",3);
        }
}



im sure you can get the jist of it

That spoon feed though lol

yeah that's not a spoonfeed
that's a "here's an example of fileobjects, now figure how to use them"

if that was spoonfeeding then there would be no way to teach someone

I was kidding, lol, it's better to learn from something than don't learn at all