Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Quartz

Pages: 1 ... 3 4 5 6 7 [8] 9 10 11 12 13 ... 22
106
Modification Help / Re: [INFORMATION] SimObjects
« on: October 23, 2015, 07:32:12 PM »
Me and Trinick were talking about this a while ago, it seems that simObjects and simSets won't allow you to associate functions with them. The weird part is that doing echo(isFunction(simObject,funcName)); returns true, however when you try calling them, it doesn't work.
That is really odd.

On the other hand, you can do everything you posted in your original post, with Script Objects/Script Groups.
Let's just pretend I was talking about that all along. I should have gone to bed earlier.

107
Modification Help / Re: [INFORMATION] SimObjects
« on: October 23, 2015, 07:30:19 PM »
ScriptObjects implement the class and superClass attributes. SimObjects do not.
Oh god, thank you! Time to edit.

108
Modification Help / Re: [INFORMATION] SimObjects
« on: October 23, 2015, 07:25:33 PM »
Did you actually test out the bill::solverubix function?
Oh stuff. All the quote symbols are somehow... different, hang on.

109
Modification Help / I smell
« on: October 23, 2015, 06:47:27 PM »
Reserved... maybe?

110
Modification Help / [INFORMATION] ScriptObjects
« on: October 23, 2015, 06:46:58 PM »
SCRIPTOBJECTS

When an object is created, it is created with an identifier and a name. The identifier is unique, but that’s not always the case with the name.
To create a new ScriptObject write this:

Code: [Select]
new ScriptObject(foo);This creates a new ScriptObject called foo. It's ID is unknown, but the prior command will return the identifier. Therefore you can do this:
Code: [Select]
$myFoo = new ScriptObject(foo);$myFoo equals to the identifier of the ScriptObject called foo. E.g: "echo($myFoo);" => "1337"
These ScriptObjects can contain both data and functions, which are called "methods and fields", when we're dealing with objects. To assign a value to a given field, you can do these commands:

Code: [Select]
foo.data = "bar";or
Code: [Select]
$myFoo.data = "bar";or
Code: [Select]
1337.data = "bar";These 3 commands will do the same thing in this context. However, if you have more than 1 object called foo, the game won't know which one you want to reference. Therefore you could assign the wrong object's field called "data" to "bar". This is why you want to make sure that the names are unique OR that you keep track of your objects' identifier.
This works with arrays too:

Code: [Select]
$myFoos[0] = new ScriptObject(foo);
$myFoos[1] = new ScriptObject(foo);
Now if you write
Code: [Select]
$myFoos[0].data = "bar";
$myFoos[1].data = "bahh";
echo($myFoos[0].data SPC  $myFoos[1].data);
It will return "bar bahh" in console. There are other ways to be sure you "talk" about the right object too. Anyway, let's move on to something very important: Classes.
With classes, you can create objects that start out with functionality that you have defined. To create an object with a class, you do either:
Code: [Select]
$myObject = new ScriptObject(foo)
{
class = myClass;
};
or
Code: [Select]
$myObject = new ScriptObject(foo);
$myObject.class = myClass;

Hooray! We've created our first class. As we mentioned earlier, an object can contain
functions. These are called methods. To create a method for the class "myClass”, you can do this:

Code: [Select]
function myClass::myMethod(%this)
{
echo("The object with the identifier” SPC %this SPC "called myMethod”);
return "yay”;
}
NOTE: When an object’s method is called, the first parameter equals to the identifier of the object. Therefore we can set data or call other methods for this object.

Now since the object we created earlier has the class "myClass”, we can run the method by writing:
Code: [Select]
$myObject.myMethod();
NOTE: Be careful to not mistake fields for methods. $myObject.myMethod() returns "yay”, but $myObject.myMethod
does nothing, since without the brackets the game will consider $myObject.myMethod as a FIELD!

When an object contains methods, it is because it has inherited it. An object can inherit methods from 3 places:
•   A class.
•   A superclass.
•   The object’s name.

To concretize this, let’s imagine we have a cat called Bill. Animals can eat things, therefore Bill can eat things. But Bill is a cat too, therefore he can purr! Bill is very special cat as well. That’s because he can do a cool trick, where he solves a Rubik’s cube. If Bill was a ScriptObject, he would look like this:

Code: [Select]
$myPet = new ScriptObject(Bill)
{
superclass = Animal;
class = Cat;
};

function Animal::eat(%this, %target)
{
//insert eat code
%this.hunger = 0;
echo(%this.getName() SPC "has eaten” SPC %target);
}

function Cat::purr(%this)
{
//insert purr code
echo(%this.getName() SPC "won’t stop purring!”);
}

function Bill::solveRubiksCube(%this, %cube)
{
//insert your simple solving code
echo(”Wow!” SPC %this.getName() SPC "actually solved" SPC %cube SPC ", a Rubik’s Cube. Does Mensa accept cats?”);
}

Now we’ve created 3 methods with 3 different namespaces. But since Bill’s class is "Cat”, his superclass "Animal” and his name is "Bill” – he can use ALL the methods within these namespaces! That’s great for Bill.
This means these three commands will work:

Code: [Select]
$myPet.eat("Tonce”);
$myPet.purr();
$myPet.solveRubiksCube( new ScriptObject(cube1) { class = RubiksCube; } );
This will output:
Code: [Select]
Bill has eaten Tonce
Bill won’t stop purring!
Wow! Bill actually solved (objectIdentifierHere), a Rubik’s Cube. Does Mensa accept cats?
ScriptObjects are very useful because, it introduces Object-oriented programming into TorqueScript.

Some helpful commands:
Code: [Select]
obj.dump(); - Dumps all methods and fields for a specified object.
tree(); - Opens a GUI where you can inspect objects in their hierarchy.

Sorry for the semi-stuffty layout. If something is off (either content or layout), please inform me.

111
Modification Help / Re: [Long Term RPG Project] "Rosemarble"
« on: October 23, 2015, 04:43:22 PM »

112
Modification Help / Re: Tutor / Teacher?
« on: October 14, 2015, 07:17:01 AM »
Search - seriously, use it. 99% of questions have already been asked, and answered. And nobody is paid to be here and help you.
When I can't find the answer with the Search function, I tend to make a Google Search with a site specified, e.g: "AIPlayer methods Site: blockland.us"

113
Gallery / Re: The Flying Dutchman WIP
« on: October 13, 2015, 12:13:30 PM »
it feels like it only looks this good cause of shadows
Yeah, but he used vanilla bricks too.

114
well, Into each life some rain must fall, and to much is falling in yours.
I live in Scandinavia, we're rain-hardened.

115
Modification Help / Re: Saving objects as *.cs or a third saving system
« on: October 13, 2015, 02:50:18 AM »
What you can do is set the objects as a class name and then save them. This is what I do for my job system, each job has an object, and it saves as a class name of "Job", that way, I use Job::onAdd(%this) to do the rest when I exec them.
Yeah, this makes the whole process more smooth and less prone to errors.

116
The inkspots are better different

This is all I can agree to.

117
Modification Help / Re: Spawning an item at any coordinate
« on: October 12, 2015, 03:47:24 PM »
Don't know why Quartz was talking about datablocks.
I think I misread the topic before it got edited.

118
Modification Help / Re: Saving objects as *.cs or a third saving system
« on: October 12, 2015, 03:44:45 PM »
Thanks everyone, I will take this into consideration.
I think I'll use the methods to do the job, since I need ALL of the information in the object groups.

119
Gallery / Re: A City Build - WIP
« on: October 12, 2015, 05:14:45 AM »
Immaculate quality! Nothing less than expected.

120
Modification Help / Re: Spawning an item at any coordinate
« on: October 12, 2015, 04:46:08 AM »
Alright, thank you. Is there a website or some sort of documentation that lists all of the variables for new items that I can customize?
You could take a look at the datablocks in-game. Start up a server and write "tree();" in console. This opens a new window that inspects and modifies game information.

Pages: 1 ... 3 4 5 6 7 [8] 9 10 11 12 13 ... 22