Author Topic: What is this code and how does it not cause an error  (Read 2134 times)

In jj storms City RPG scriptobjects.cs there is a couple of lines (Line 90 through 119) that says

Code: [Select]
id      = $ CityRPG::jobs::ID;And so on I would like to know how this works, I get its assigning a variable to Id but I don't know how I could get Id later when I need it so for a salary it would be asigned to
Code: [Select]
pay

In order to tell if it really is syntactically correct or not we need the surrounding lines as well.

well I know it works, I didn't type it its from JJStorms CityRPG I just want to know how id is not a variable it just says
Code: [Select]
id      = $CityRPG::jobs::ID

Like Ipquarx said, if you want us to tell you how it works, then we'll need the surrounding lines.

It's probably inside of a ScriptObject, or any other type of object.

Code: [Select]
function JobSO::addJob(%so, %path) {
%jobID = %so.getJobCount() + 1;
exec(%path);
%so.job[%jobID] = new scriptObject()
{
id = $CityRPG::jobs::ID;

name = $CityRPG::jobs::name;
invest = $CityRPG::jobs::initialInvestment;
pay = $CityRPG::jobs::pay;
tools = $CityRPG::jobs::tools;
education = $CityRPG::jobs::education;
db = $CityRPG::jobs::datablock;
hostonly = $CityRPG::jobs::hostonly;
adminonly = $CityRPG::jobs::adminonly;
outfit = $CityRPG::jobs::outfit;

sellItems = $CityRPG::jobs::sellItems;
sellFood = $CityRPG::jobs::sellFood;
sellServices = $CityRPG::jobs::sellServices; // Unused.
sellClothes = $CityRPG::jobs::sellClothes;

law = $CityRPG::jobs::law;
canPardon = $CityRPG::jobs::canPardon;

thief = $CityRPG::jobs::thief;
hideJobName = $CityRPG::jobs::hideJobName;

bountyOffer = $CityRPG::jobs::offerer;
bountyClaim = $CityRPG::jobs::claimer;

laborer = $CityRPG::jobs::labor;

tmHexColor = $CityRPG::jobs::tmHexColor;
helpline = $CityRPG::jobs::helpline;
};
please explain what each thing does also what do the arguments %so and %path

JobSO Is the name of a scriptobject that (assumably) contains all the information regarding jobs types. %so, the first argument, is the scriptobject that the function was called on. That would be the JobSO that the function is being called on. The %path argument contains a path to a cs file that has a bunch of global variable definitions, that, once executed, will set the global variables that are used to create a job. Once the variables are set it creates a new variable inside of the JobSO with all the information about the new job.

I really get the feeling that with all these coding help topics you should try to work on your basic understanding of torquescript and coding before trying to dive into more complicated things.  A lot of the problems that you are posting could easily be solved with a search if you understood just a little more about what was going on in the code.

I really get the feeling that with all these coding help topics you should try to work on your basic understanding of torquescript and coding before trying to dive into more complicated things.  A lot of the problems that you are posting could easily be solved with a search if you understood just a little more about what was going on in the code.
i did not make this and there is no problem I'm just trying to understand torque more up until now I have only done weapons

It's valid because that's how object declarations work. You don't need to tell it you're defining a variable because it's already expecting it

Ok I see so its the same thing as a variable praticly?

Ok I see so its the same thing as a variable praticly?
%obj = new ScriptObject(Thing)
{
    stuff = "hello";
    blah = 123;
};
does the same as
%obj = new ScriptObject(Thing){};
%obj.stuff = "hello";
%obj.blah = 123;

In addition to Zeblote's example, you could also use the object name (the stuff between the parenthesis after the class name, in this case "Thing"):

Thing.stuff = "hello";
Thing.blah = 123;

In addition to Zeblote's example, you could also use the object name (the stuff between the parenthesis after the class name, in this case "Thing"):

Thing.stuff = "hello";
Thing.blah = 123;
ok thanks one more thing, does the %obj argument do anything other than tagging it to object?

It's so you can use it later in the function easier. You don't need it.

It's just a variable holding the reference to the created script object

An argument is what you put in the parenthesis when you call or define a function