Difference between revisions of "Tutorial:Sims 3 In Depth Scripting"

From SimsWiki
Jump to: navigation, search
(Deriving A Class)
(Classes)
Line 18: Line 18:
 
<br>
 
<br>
 
<br>
 
<br>
There are a few different types of classes. Here's a chart of them and what you would use them for.
+
There are a few different types of classes. Here's a chart of them and what you would use them for. These are not all of them. They are just the ones that are commonly used throught Sims 3 scripting.
  
 
{|width="80%"  border="1" cellpadding="2" cellspacing="0"
 
{|width="80%"  border="1" cellpadding="2" cellspacing="0"

Revision as of 16:14, 4 October 2011

Contents

Intro

My goal in this guide is to help the complete "noobs" at scripting languages and put them in words that they can describe. This guide assumes you know absolutely nothing about C# and you really want to learn how to make those cool scripts for objects that you see all the time. This will go over methods, classes, strings, overrides, and more. You should have a very, very basic understanding of the InteliSense system that Visual Studio provides as well as a basic idea of using Reflector.
THIS IS A WORK IN PROGRESS

Requirements

  • Microsoft Visual C# Express 2008 - I will call this program VS for short. I highly reccomend that you use this version instead of the 2010 as it seems to not work correctly when it comes to referencing.
  • Sims3 Package Editor - I call it S3PE for short in this guide.
  • Sims3 Object Cloner - S3OC isn't mentioned very much in this guide until the very end. You'll normally use this program for finding what objects are derived from what and cloning items to change their scripts.
  • .NET assembly browser/decompiler - I use Reflector 6.8. You can get the trial version of Reflector 7 if you want.
  • A good understanding of using text editors and computers. Programming is not for the people who don't know how to use computers.

Lets do this!

Classes

Classes are the building blocks of scripting. They allow you to group up parts of your code and to "derive" parts of code. You will ALWAYS start off your code with a class of some sort.
Still don't understand the concept of a class? Think of them as groups. You group your code together. Similar to how baseball would be under the group of sports. Now, there are a bunch of different types of sports like football, tennis, and volleyball. All of them are sports because they are grouped under sports. It's common knowledge. When you think of baseball, you think of sports. When you think of sports, you think of baseball.

There are a few different types of classes. Here's a chart of them and what you would use them for. These are not all of them. They are just the ones that are commonly used throught Sims 3 scripting.

Type of Class How to use it

class

This is normally used right after the namespace. It is typically followed by a public/private class.

public class

This is used right after you have a class, however a class is not needed to use "public class". You can start off with "public class" right after your namespace. This makes your class accessible by anyone trying to use your code.

private class

This is used for making a class unaccessable by anyone but you. This means that if someone references your DLL they will not be able to use methods inside that class.


Deriving A Class

Deriving a class means that you're basing your class off of another class. Let's take a look at some Sims 3 objects. When you go into reflector and look at the FishTankModern class which is found under Sims3.Gameplay.Objects.Decorations.
When you look at this code you will notice a " : " after FishTankModern. This is telling us to derive, or use, the same exact functions, or methods, that FishTank has. It's really that simple.

Why should I derive off of another class? Object scripting in Sims 3 without deriving will make your life a living hell and Sims 3 popping up a bunch of errors when you try to run it. Like I said, deriving will allow us to use those same functions without having to create that part of code ourselves. Every single object is derived off of GameObject in one way or another. This is the class that allows objects to show interactions, do certain stuff, get the catalog names, etc. If you look at our example of FishTankModern and click on FishTank, Reflector will bring you to the FishTankClass. As you can see, FishTank is also derived off of GameObject. This gives any object derived off of FishTank all the methods of GameObject and FishTank.

I still don't get it... Lets take a look at a Dell computer. Notice how I'm saying a Dell computer? It's not just any type of computer, it's a Dell computer. A Dell computer is the same as a regular computer, but has different/similar/enhanced features. If we were to think of a Dell computer as being derived off of a class, it would be something like "public class DellComputer : Computer". This gives the DellComputer the same features as Computers but will allow us to add in even more methods without having to change Computer.
Now we have not just any type of DellComputer but a DellInspirion. We want the DellInspirion to have the same features as a DellComputer would have but more added to it. We would do "public class DellInspirion : DellComputer". Again, the DellInspirion is a DellComputer and the DellComputer is a Computer. So the DellInspirion would be able to use methods from DellComputer and Computer. You can keep going on with this for ever and ever.

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox