Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I use classes?
Kullin1337 Offline
Junior Member

Posts: 8
Threads: 2
Joined: Apr 2015
Reputation: 0
#1
How do I use classes?

Hi, I just read this and I wonder something. How do I use classes? I need to use it for a project in school.
04-20-2015, 12:21 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#2
RE: How do I use classes?

(04-20-2015, 12:21 PM)Kullin1337 Wrote: Hi, I just read this and I wonder something. How do I use classes? I need to use it for a project in school.

That's never something I've used for scripting in amnesia. What do you need it for?

Trying is the first step to success.
04-20-2015, 12:28 PM
Find
Kullin1337 Offline
Junior Member

Posts: 8
Threads: 2
Joined: Apr 2015
Reputation: 0
#3
RE: How do I use classes?

(04-20-2015, 12:28 PM)FlawlessHappiness Wrote:
(04-20-2015, 12:21 PM)Kullin1337 Wrote: Hi, I just read this and I wonder something. How do I use classes? I need to use it for a project in school.

That's never something I've used for scripting in amnesia. What do you need it for?
I only need to show our teacher that I know how it works and that I can use it.
I was thinking that I could add some code locks (or similar) just so it's there.
But I have no idea how to do it in Amnesia.
(This post was last modified: 04-20-2015, 12:53 PM by Kullin1337.)
04-20-2015, 12:32 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: How do I use classes?

I might be wrong, but from my impression, C++ does not use classes. It is not an object-oriented language, and I don't expect AngelScript to be either, as it's based on it.

But if classes do work (something I've never tried), then I suppose they might work similarly to Java. If you're looking for a similar language that does use classes (and a lot too), then Java is probably what you're after.

In short, a class is a blueprint of some code. It can be called several times and used in different scenarios, but each class instance is unique and separate, storing its own values in the defined variable it was created as. Let's say you create a class that will trigger an explosion with lots of sounds, particles and other effects. The class itself will never say where these effects are applied, because that would cause it to only work once. It instead defines those specific values as parameters for the caller to define. When you have your class up, you can call it from somewhere else and then only define the necessary bits of information, like the location for the effects.

Using classes will save you space as you will be reusing the same class code several times. It is defined as an object, which is an advanced type of variable, contrary to a primitive type like an int or float.

04-20-2015, 04:20 PM
Find
Kullin1337 Offline
Junior Member

Posts: 8
Threads: 2
Joined: Apr 2015
Reputation: 0
#5
RE: How do I use classes?

(04-20-2015, 04:20 PM)Mudbill Wrote: I might be wrong, but from my impression, C++ does not use classes. It is not an object-oriented language, and I don't expect AngelScript to be either, as it's based on it.

But if classes do work (something I've never tried), then I suppose they might work similarly to Java. If you're looking for a similar language that does use classes (and a lot too), then Java is probably what you're after.

In short, a class is a blueprint of some code. It can be called several times and used in different scenarios, but each class instance is unique and separate, storing its own values in the defined variable it was created as. Let's say you create a class that will trigger an explosion with lots of sounds, particles and other effects. The class itself will never say where these effects are applied, because that would cause it to only work once. It instead defines those specific values as parameters for the caller to define. When you have your class up, you can call it from somewhere else and then only define the necessary bits of information, like the location for the effects.

Using classes will save you space as you will be reusing the same class code several times. It is defined as an object, which is an advanced type of variable, contrary to a primitive type like an int or float.
I know what a class is and I also know that they do exsist in both C++ and AngelScript, I just don't know how to use then in AngelScript.

Anyways, thank you for the response! (:
04-20-2015, 04:41 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#6
RE: How do I use classes?

(04-20-2015, 04:20 PM)Mudbill Wrote: I might be wrong, but from my impression, C++ does not use classes. It is not an object-oriented language, and I don't expect AngelScript to be either, as it's based on it.

But if classes do work (something I've never tried), then I suppose they might work similarly to Java. If you're looking for a similar language that does use classes (and a lot too), then Java is probably what you're after.

In short, a class is a blueprint of some code. It can be called several times and used in different scenarios, but each class instance is unique and separate, storing its own values in the defined variable it was created as. Let's say you create a class that will trigger an explosion with lots of sounds, particles and other effects. The class itself will never say where these effects are applied, because that would cause it to only work once. It instead defines those specific values as parameters for the caller to define. When you have your class up, you can call it from somewhere else and then only define the necessary bits of information, like the location for the effects.

Using classes will save you space as you will be reusing the same class code several times. It is defined as an object, which is an advanced type of variable, contrary to a primitive type like an int or float.

To me, this sounds like when I make up my own functions.
Now I've never used classes, so eh...

Example.
PHP Code: (Select All)
void OnStart()
{
ChangeTheseEntities(10"mansion_door"false);
}

void ChangeTheseEntities(int alAmountstring &in asEntitybool abActive)
{
for(
int i=1;i<=alAmount;i++)SetEntityActive(asEntity+"_"+iabActive);

With this script I'd be able to call the line in void OnStart(), give it some parameters and it'll then do what I told it to. In this case, set a lot of entities inactive.

Trying is the first step to success.
(This post was last modified: 04-20-2015, 06:31 PM by FlawlessHappiness.)
04-20-2015, 05:06 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#7
RE: How do I use classes?

Classes do exist in AngelScript but are rarely used for anything in Amnesia. I'm bringing up an example here of how you can set one up (bringing in a random idea of using a class).

const string doorName = "mansion_1";

class OpeningDoorUpdate
{
    private int currentDoorState;
    private float throwImpulse;
    
    OpeningDoorUpdate()
    {
        this.currentDoorState = GetSwingDoorState(doorName);
        this.throwImpulse = 50.0f;
    }
}

Just a brief example of how its setup and nothing is gonna happen when you input it, but if I'm not mistaken, this is briefly how its setup.

Derp.
(This post was last modified: 04-20-2015, 08:38 PM by Neelke.)
04-20-2015, 08:38 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#8
RE: How do I use classes?

(04-20-2015, 05:06 PM)FlawlessHappiness Wrote: To me, this sounds like when I make up my own functions.
Now I've never used classes, so eh...

Yes, it's essentially the same thing. The most notable difference (I think) is that classes are usually called externally, so that you may use separate files. At least that's how they work in Java, but they might work differently here since C++ doesn't really seem like the language that loves many separate files. Idk.

04-20-2015, 09:20 PM
Find
Kullin1337 Offline
Junior Member

Posts: 8
Threads: 2
Joined: Apr 2015
Reputation: 0
#9
RE: How do I use classes?

(04-20-2015, 09:20 PM)Mudbill Wrote:
(04-20-2015, 05:06 PM)FlawlessHappiness Wrote: To me, this sounds like when I make up my own functions.
Now I've never used classes, so eh...

Yes, it's essentially the same thing. The most notable difference (I think) is that classes are usually called externally, so that you may use separate files. At least that's how they work in Java, but they might work differently here since C++ doesn't really seem like the language that loves many separate files. Idk.
It should work from a separate file, that's how it works in C++.
I know how write a class, but I have no idea how I use it in Angelscript and that's my problem.
04-21-2015, 11:52 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#10
RE: How do I use classes?

(04-21-2015, 11:52 AM)Kullin1337 Wrote:
(04-20-2015, 09:20 PM)Mudbill Wrote:
(04-20-2015, 05:06 PM)FlawlessHappiness Wrote: To me, this sounds like when I make up my own functions.
Now I've never used classes, so eh...

Yes, it's essentially the same thing. The most notable difference (I think) is that classes are usually called externally, so that you may use separate files. At least that's how they work in Java, but they might work differently here since C++ doesn't really seem like the language that loves many separate files. Idk.
It should work from a separate file, that's how it works in C++.
I know how write a class, but I have no idea how I use it in Angelscript and that's my problem.

From my experience you cannot call anything from a seperate file... If you can, I've made a huge mistake during the development of my CS Monsters...
Oh my, if this turns out that you can keep one script throughout a lot of maps... that would be aaaaawesome

Trying is the first step to success.
04-21-2015, 12:00 PM
Find




Users browsing this thread: 1 Guest(s)