How do I use classes? - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: How do I use classes? (/thread-29840.html) Pages:
1
2
|
How do I use classes? - Kullin1337 - 04-20-2015 Hi, I just read this and I wonder something. How do I use classes? I need to use it for a project in school. RE: How do I use classes? - FlawlessHappiness - 04-20-2015 (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? RE: How do I use classes? - Kullin1337 - 04-20-2015 (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. 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. RE: How do I use classes? - Mudbill - 04-20-2015 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. RE: How do I use classes? - Kullin1337 - 04-20-2015 (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. Anyways, thank you for the response! (: RE: How do I use classes? - FlawlessHappiness - 04-20-2015 (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. 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() RE: How do I use classes? - Neelke - 04-20-2015 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). Code: const string doorName = "mansion_1"; 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. RE: How do I use classes? - Mudbill - 04-20-2015 (04-20-2015, 05:06 PM)FlawlessHappiness Wrote: To me, this sounds like when I make up my own functions. 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. RE: How do I use classes? - Kullin1337 - 04-21-2015 (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. I know how write a class, but I have no idea how I use it in Angelscript and that's my problem. RE: How do I use classes? - FlawlessHappiness - 04-21-2015 (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. 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 |