04-20-2015, 12:21 PM
Pages: 1 2
04-20-2015, 12:28 PM
04-20-2015, 12:32 PM
(04-20-2015, 12:28 PM)FlawlessHappiness Wrote: [ -> ]I only need to show our teacher that I know how it works and that I can use it.(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 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.
04-20-2015, 04:20 PM
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.
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:41 PM
(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.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.
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.
Anyways, thank you for the response! (:
04-20-2015, 05:06 PM
(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:
void OnStart()
{
ChangeTheseEntities(10, "mansion_door", false);
}
void ChangeTheseEntities(int alAmount, string &in asEntity, bool abActive)
{
for(int i=1;i<=alAmount;i++)SetEntityActive(asEntity+"_"+i, abActive);
}
04-20-2015, 08:38 PM
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).
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.
Code:
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.
04-20-2015, 09:20 PM
(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-21-2015, 11:52 AM
(04-20-2015, 09:20 PM)Mudbill Wrote: [ -> ]It should work from a separate file, that's how it works in C++.(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.
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, 12:00 PM
(04-21-2015, 11:52 AM)Kullin1337 Wrote: [ -> ](04-20-2015, 09:20 PM)Mudbill Wrote: [ -> ]It should work from a separate file, that's how it works in C++.(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.
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
Pages: 1 2