Author Topic: Is this a good enough tutorial?  (Read 2216 times)

I was thinking the console is super useful.  So I wrote a very long explanation on how to use one command.  So uh- tell me if this helps you understand torque's structure at all.  Since that's what it mostly covers.



Hi there.

I want to teach you how to use the console.
It's not necessary to have fun with this game.
But it helps out a ton if you wanna do cool stuff.

So.
Let's uh, start with... teleportation.  Aight?
To teleport someone- we need to find the someone we're teleporting.

Each player has at least two object associated with them.
The first one is the GameConnection.  Or the client.  We'll call it a client, because that's how its refered to in ALOT of code. But just remember, it's the Game Connection.  Because that describes- perfectly- what it does.  Its a persons connection to the game.  It stores their Blockland ID, their Name, their LANname, all of their avatar preferences, etc.  Just like- information on who that person is.  If you delete it- the person is removed from the game.

The second object we'll be using is the Player object.  This is the little blockhead dude you see in the game.  The one you shot in the head and tea-bagged before he dissappeared in a cloud of dust.  The Player has health, a position, and items.

All objects in blockland have an object ID.  This is- a non-negative integer you can use in the console to mess with an object.  So like- if I look at the ground and type /getid.  I get an object id for the ground.  If I type in the ground's object id .delete();  it will delete the ground.
1337.delete();

Object ID's are assigned in the order the objects are created.  If I spawn before someone else, my player objects ID will be lower than their player object ID.
Same with Client objects.  If Badspot joins my server 30 minutes into a game.  My GameConnection Object ID will be lower than his.

Object IDs should bot be confused with Blockland IDs.  A blockland ID is basically just an invoice number.  This is the 13426th purchase of the game.

Ok so- forget i kinda got off track.

OK so an object can be found if you know it's ID number.  But it's real loving difficult to find the ID number of an object if you don't know where that object is.  And besides that it's not like we can use /getid on a client object.  A client object isn't represented visually- anywhere in the game.  All of your gui elements such as your item inventory, the main menu, the escape menu.  These have object Ids too.  How can we find them?  We can't use /getid on them.

There is a way- by searching through all objects currently created and comparing what we know about the object we're looking for to these objects.  But that takes a long time- And is loving impractical.  Like searching for a needle in a haystack.  Wouldn't it be better if these objects were sorted somehow?  Like if all player objects were in the same folder or something. ...  Oh wait yeah, that's how it works.

SimGroups.  Simulated groups.  Basically just information directories.  So if we wanted to keep a list of all of the clients connected to the game, we could make a client group, and add all of he clients to the client group.  Great.  That certainly reduces the size of the list we have to search through.  15 people on the server, that's only 15 entries we have to look through.
Only it's not a list of 15 objects, because we still have no way of finding the client group object we just created.  So it's still the 8000 or so objects created when we started the game.

This is where names come in.  Blockland does have a group for clients.  it's called ClientGroup.  If you type in ClientGroup.getObject(0);.  It will return the object ID of one of the clients currently in the game.  getObject(1); will return the next client, and so on.
...
Actually I'm- well I'm technically correct here. It WOULD return the object ID.  But you wouldn't see it.  You didnt tell the game to do anything with the object ID, so it would just throw it away.  If you wanted to... SEE the object id.  You would want to do echo(ClientGroup.getObject(0));  This will print the object ID to the console.  If you then took that ID number and did ID#.delete("lolkikd"); then it would kick that person from the game. Teehee.
You could also do ClientGroup.getObject(0).delete("hahahaha"); repeatedly.  And you would eventually kick everyone from the game.You're basically saying:  Search the list of named objects for an object named "ClientGroup". Pretend that object is a folder, and grab the first object in that folder. Then delete the object you grabbed.

Ok so now I should explain tags and functions.  Most of what we've been using so far are functions.  getObject(); is a function.  delete(); is a function.  quit(); is a function too.  That quits your game btw.  In case you couldn't tell.
One of the functions you will be using alot is the findclientbyname("name"); function.  This function- basically just searches through the client group for a connection with the same ingame name as the one you typed in. Which is great.  Cause instead of typing:
if(isObject(ClientGroup)){for(%i=0;%i<ClientGroup.getCount();%i++){if(ClientGroup.getObject(%i).name $= "Name"){ClientGroup.getObject(%i).delete("lol");}}}
Every time I want to kick someone.  I can just type: findclientbyname("Name").delete("lol");
Greaaaaat time savers.

Tags are a way of storing information.  If I knew someone was a national socialist sympathizer.  And I wanted to keep track of that.  I could do something like this: findclientbyname("RiddlerWasReicht44").isnational socialistsympathizer = "jawohl";  And from then on, as long as he stays in the server I can look that up about him.  Just- echo(findclientbyname("Name").isnational socialistsympathizer);  If he's a sympathizer, it says "jawohl".  Otherwise- it does nothing, or returns a blank line.  I can't remember which.

Ok so now you know about Groups, functions, and tags.  That's-  that's all you need I think.
By default, when a player spawns ingame.  The player object ID is stored on the client object of the person who owns it.
So something like findclientbyname("NewGuyJoe").player = 198347;  Or to be more accurate the game probably does something like 197220.player = 198347;
And likewise, the client object ID is stored on the player.
So something like: 198347.client = 197220;

In addition the player also has a position tag stored on it.  Something like "30 -12 4.5".  If you've ever taken math beyond the 7th grade level, you've probably run into a coordinate system.  These are just- x y z coordinates in relation to the center of the world.

SO.  With all of this in mind we can say.
findclientbyname("Name").player.position = "0 0 10"; to teleport you 10 units above the center of the world. (That's 20 brick studs btw)
OK. SO there.  It's done.  That's how you can teleport someone with the console.

You could also use findclientbyname("Name").player.setTransform("0 0 10 0 0 1 0");  And that would technically be more correct, since setTransform is a part of the default game engine, while updating the position tag to move someone seems to just be a hack some clever developer put in at some point.

Pretend this thumbs down is a thumbs up. I don't have a thumbs up emoji.

Pretend this thumbs down is a thumbs up. I don't have a thumbs up emoji.


positions are just variables stored in memory
as well as player scale
don't tinker with setting scale because it forgets some stuff up (findclientbyname(lel).player.scale)
but yes it's a good tutorial

Well it's descriptive enough, but really annoyingly written too. The humor doesn't work man.


I think putting the lines of code in [ code] blocks would help make the tutorial more readable, along with [ hr] where appropriate and better sectioning into specific topics/goals.
is there anyway to temporarily disable bbcode for a post so i don't need the above spaces?

It's called a field, not a tag

Cool.  So adding structure, headings, sections.
Pictures would probably help too.

Definitely could use structure, currently it's focused around doing one thing but if you expand it you could number off different sections. Perhaps wait on displaying if(isObject(ClientGroup)){for(%i=0;%i<ClientGroup.getCount();%i++){if(ClientGroup.getObject(%i).name $= "Name"){ClientGroup.getObject(%i).delete("lol");}}} until more explanation has been given. Code blocks would also be good.

Maybe add something a bit more useful just for fun, like teleporting a player upwards from their current position.
Code: [Select]
findclientbyname("Name").player.position += "0 0 10";
or whatever it is

Well it's descriptive enough, but really annoyingly written too. The humor doesn't work man.
It seemed more interesting than your usual tutorial to me.

Code: [Select]
findclientbyname("Name").player.position += "0 0 10";

It would be
findClientByName("Name").player.setTransform(vectorAdd(findClientByName("Name").player.getPosition(), "0 0 10"));

EDIT:
Reworded.
« Last Edit: January 20, 2016, 02:50:09 PM by Darksaber2213 »

certainly does its job but the grammar structure really bothers me as a reader and the attempt at humor is pretty tryhard imo

I gave reformatting and organizing the tutorial a go. It's not complete so feel free to add on/modify stuff for correctness.


While knowledge of the console is not necessary to have fun in Blockland, it will allow you to do much more.


Accessing the Console

To access the console in Blockland, press the tilda (~) key while in-game. This key is located below escape, at the top-left of your keyboard.


Basic Concepts

Client- a person's connection, or Game Connection, which stores information such as their name, game settings, etc. If you delete this the person will be removed from the game.
  • client.player will get you the client's corresponding player object

Player- the little blockhead dude you see in the game. The Player has health, a position, and items.
  • player.client will get you the player's corresponding client object

Object ID- a non-negative integer assigned to all objects. You can use in the console to mess with an object. 
  • /getID- returns the ID of the object you're looking at
  • Object ID's are assigned in the order the objects are created
  • Object IDs should bot be confused with Blockland IDs. A blockland ID is basically just an invoice number.
An object can be modified if you know it's ID number. However, we can't use /getid on a client object, gui element, or any other non-visual object. In order to get these IDs, we must learn about SimGroups.

SimGroups- Simulated groups that are basically just information directories.
  • ClientGroup- the SimGroup for clients
Knowing this, ClientGroup.getObject(0); will return the object ID of one of the clients currently in the game. ClientGroup.getObject(1); will return the next client (if it exists), and so on. However, nothing will appear in the console just by typing this in. We haven't told the console what to do with this information.

Functions- Operations that perform a task
  • Function names are always followed by an open parenthesis, any arguments, and a closed parenthesis
  • getObject() is a function

echo()- A function that prints the given value out to the console
  • echo("hello") would print out the string "hello" in the console
To view the object ID of the first object in the ClientGroup, we would use echo(ClientGroup.getObject(0));

Fields- Elements attached to objects
  • player.position- position is a field of player
Adding your own fields to objects is simple.
Code: [Select]
findclientbyname("Name").fieldname = "value";
This would add a field "fieldname" to the specified client object, and set its value to the string "value"


Server Applications

1. Deleting
Deleting is one of the most basic applications of the console. Type /getID to get the ID of the object you're looking at. Then use
Code: [Select]
<objectID>.delete();
to remove the object from the game. (Replace <objectID> with the integer value provided by /getID)

2. Teleportation
A simple first application of the console is teleportation. To teleport someone, we need to first find the player object we want to teleport. This can be done by finding the client with specified name, then retrieving the player field of that client. After we have the player, we then need to access the position field of the player and set it to our own value.

To teleport a player 20 brick studs above the center of the world, use:
Code: [Select]
findclientbyname("Name").player.position = "0 0 10";

But what if we want to teleport someone upwards from their current position? Then we would need to set their transform to their current position vector added with the vector in the direction we want to teleport them.
Code: [Select]
findClientByName("Name").player.setTransform(vectorAdd(findClientByName("Name").player.getPosition(), "0 0 10"));