Different syntax

Post » Tue Dec 29, 2009 8:30 pm

player->startcombat
startcombat player


What are the differences in these two syntax. I know the difference in other languages, but this is confusing how they have this structured. In another standard language the first would end
up being OOP, the second one would be standard procedural syntax. Is it the same in this language..so they are both basically the same? Which one would be considered "best practice".
I have seen a lot examples of both.
User avatar
Nuno Castro
 
Posts: 3414
Joined: Sat Oct 13, 2007 1:40 am

Post » Tue Dec 29, 2009 4:52 pm

I think they're not the same.
I don't think that "player->startcombat" would even work, how could it force player to start fighting? The other one forces the NPC that has this particular script attached to start fighting with player.
User avatar
Far'ed K.G.h.m
 
Posts: 3464
Joined: Sat Jul 14, 2007 11:03 pm

Post » Tue Dec 29, 2009 4:12 pm

StartCombat causes the calling object to attack the actor passed in the first parameter.

E.g. "some_npc"->StartCombat, "player" will make some_npc attack player.
The same thing will happen if you call StartCombat, "player" from the local script of some_npc.
User avatar
Lance Vannortwick
 
Posts: 3479
Joined: Thu Sep 27, 2007 5:30 pm

Post » Tue Dec 29, 2009 7:34 am

The majority of operations need to have an object to act on. By default the command would act on the object the script is attached to (This is a bit more complicated with global scripts, so I am ignoring them for now).

So if you have a script running on an NPC with the id "NPC1" then the script
startcombat, "NPC2"
would cause "NPC1" to start combat with NPC2. You could also use
"NPC1"->startcombat, "NPC2"
which would do exactly the same thing as in both cases startscript is called on the NPC1.

If you have a script attached to another object, lets say a chest, and wanted to get "NPC1 to start combat with NPC2 then this wouldn't work:
startcombat, "NPC2"
as the script is attached to the chest, so this tries to get the chest to start combat with NPC2. Insead you would have to directly reference the entity you want the startscript to be called on. Hence you would have to use
"NPC1"->startcombat, "NPC2"
.

In essence, commands that use objects will by default be called on the entity the script is attached to. Using: "actorid"-> before the command allows you to specify an alternative entity to call the function on.

I hope now that you understand that your example is slighty wrong and they are not infact equilivent. This
player->startcombat
won't compile, as startcombat takes a single argument indicating what should be attacked.

This however would cause the entity that the script is attached to to attack the player
startcombat player

User avatar
Jordan Moreno
 
Posts: 3462
Joined: Thu May 10, 2007 4:47 pm

Post » Tue Dec 29, 2009 9:41 pm

Nice, thanks for that. That makes a lot more sense.
User avatar
Jessica Stokes
 
Posts: 3315
Joined: Fri Jul 28, 2006 11:01 am


Return to III - Morrowind