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


Thread Rating:
  • 14 Vote(s) - 2.93 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge Threadᆦ ᆦ ᆦ
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
#51
RE: [CHALLENGE THREAD]

Is "global" supposed to refer to primitives that can be accessed from anywhere within the .hps script file, or is it supposed to refer to primitives that can be shared between hps files? (I really hope I'm using the word "primitive" correctly in this situation. >_> )

(04-14-2012, 08:38 PM)Your Computer Wrote: There are reasons why you would want to do this at the time of instantiation rather than after
Can you give me some examples of these reasons?

(This post was last modified: 04-14-2012, 09:06 PM by Homicide13.)
04-14-2012, 09:03 PM
Find
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#52
RE: [CHALLENGE THREAD]

(04-14-2012, 08:10 PM)Homicide13 Wrote: This is what I've been able to do with classes so far - it's just a simple script that fades the screen in and out every two seconds by using a class to call the FadeIn/Out functions instead of doing it normally.
http://www.mediafire.com/?fyv0kaloztgworc

However, what I don't understand so far is why I would use classes instead of just globally declaring everything.

Also I have no idea what class constructors are or what they're supposed to do.
Just from looking at your code I have a much better understanding of what classes are, and how they can be used. Just a few questions, could someone tell me what the following pieces of code are doing?

TestClass test;
EveryOther = EveryOther == true ? false : true;

From looking at them I'd say TestClass test; is declaring the class(?), and the second is switching EveryOther's boolean state between true and false every time it is called. Is this right? or have I got it completely wrong?
But what is confusing me is the "test" part, why is that there? It is also prefixed on some other lines:
test.TestFO();
test.TestFI();
I can tell what these do, but why must it have a test. prefix?
Thanks for the help!



04-14-2012, 09:12 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#53
RE: [CHALLENGE THREAD]

(04-14-2012, 09:03 PM)Homicide13 Wrote: Is "global" supposed to refer to primitives that can be accessed from anywhere within the .hps script file, or is it supposed to refer to primitives that can be shared between hps files? (I really hope I'm using the word "primitive" correctly in this situation. >_> )

Tongue Classes aren't primitives (though they are their own data type). But, yes, things that are in the global scope can be accessed anywhere within the script, but in HPL2 it is only within that one script.

(04-14-2012, 09:03 PM)Homicide13 Wrote: Can you give me some examples of these reasons?

Let's say, for example, one of your classes has members that are supposed to reference other classes. If you try to call a method that accesses these members without first instantiating these other classes, this will crash the program, or at least exit out with an error. However, AngelScript seems to instantiate the class at the time of declaring the variable that references the object, so this may not be an issue here. There are other reasons why one would want to define their own constructors (e.g. you want a member to have a different value at construction time), but these reasons usually do not relate to accessing members that don't necessarily exist.

Tutorials: From Noob to Pro
(This post was last modified: 04-14-2012, 09:27 PM by Your Computer.)
04-14-2012, 09:27 PM
Website Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
#54
RE: [CHALLENGE THREAD]

TestClass test; takes the class "TestClass" and instances it under the name "test" (from what I can tell), and then the class variables/functions/whatever can be accessed by adding "test.". In essence, the "test." is telling to look for the "TestFO()" function under the "test" instance.

NOTE: after reading over what Your Computer wrote and thinking about things a bit, I'm pretty sure the explanation above is wrong.

EveryOther = EveryOther == true ? false : true; is an "either or" statement. A good way to write this so that it makes sense looking at it would be this: (note that as far as I know you can't use the parentheses in your actual code)

variable = ( (boolean statement) ? (option1 : option2) )

The first section is a boolean statement that returns either true or false. The second section will return option1 if the first section is true, otherwise it will return option2. What I have is pretty much a simpler way to write
"IF(EveryOther)
{
EveryOther = false;
}
else
{
EveryOther = true;
}

(04-14-2012, 09:27 PM)Your Computer Wrote: But, yes, things that are in the global scope can be accessed anywhere within the script.
Well the SetGlobalVarInt function allows variables to be accessed between scripts, so this is probably where the confusion comes from.

I think I'll call these types of variables "super global" from now on, and variables set by scripts such as "SetLocalVarInt" just "global" variables (because I assume that's pretty much what they are).

Also, I'm having trouble initializing an array within a class. It works just fine when I put it in the global scope of the script:

int[] SHealth(3,2);

but when I put it in a class:

class SuitorHealth
{
int[] SHealth(3,2);
}

It returns and "expected ';'" error and an "unexpected token '}'" error. Sad

Also also, are classes considered "object" variables? I'm not quite sure on this one.

(This post was last modified: 04-14-2012, 09:44 PM by Homicide13.)
04-14-2012, 09:27 PM
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
#55
RE: [CHALLENGE THREAD]

I'm talking about the impossibility of creating a global variable within the meaning of 1 .hps file-

Inside the global scope of one script file is the meaning of 1 .hps file. Also, classes are classes. Object Oriented Programming(C++ for instance) uses classes.

A good example is the string class. when you do this: "string sObject;" you're doing nothing else than creating an object of the class string. Each object uses the methods and attributes of the class.
Give me a minute.


For example, imagine the class People.

In C++:
PHP Code: (Select All)
Header:

class 
Person //Class
{
    public: 
//In AngelScript this is not needed(neither in C++ anyway)

        
Person(int string);
        
int getAge() const;
        
void setAge(int );

    private:
//In AngelScript you would need something like private int pAge; to declare a private member.

        
int pAge;
        
string sName;

}

//File with member function definitions:

Person::Person(int nAgestring personName)
 :
pAge(nAge), sName(personName)
{
    
//do w.e. else
}

int Person::getAge() const
{
    return 
pAge;
}

void Person::setAge(int nAge)
{
    
pAge nAge;
}

//Source code file

int main()
{
    
Person person(21"James");//person is the object. Person is the class
    
cout << person.getAge(); //<< in case you don't know << is the stream insertion operator and cout is something like print(). Prints to the screen
    
person.setAge(24);
    
cout << person.getAge();


OUTPUT:
21
24

In the header file we have the class definition(it's always best to separate definition from implementation).
Then we have the member functions implementation. I suppose you are already familiar with these things.

In the source file it creates an object: person and initializes the classes attributes(Age and Name) using the class's constructor.

Then it messes around with the Person's class object.

I hope you understood the use of classes. Now you have to think about it.

Today I dreamt the life I could live forever. You only know that when you feel it for you know not what you like until you've experienced it.
(This post was last modified: 04-14-2012, 11:17 PM by nemesis567.)
04-14-2012, 10:32 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#56
RE: [CHALLENGE THREAD]

(04-14-2012, 09:27 PM)Homicide13 Wrote: Well the SetGlobalVarInt function allows variables to be accessed between scripts, so this is probably where the confusion comes from.

I think I'll call these types of variables "super global" from now on, and variables set by scripts such as "SetLocalVarInt" just "global" variables (because I assume that's pretty much what they are).

It's easier to understand when you separate map variables from script variables. Map variables get saved within the game session, script variables do not--for HPL2.

(04-14-2012, 09:27 PM)Homicide13 Wrote: Also, I'm having trouble initializing an array within a class. It works just fine when I put it in the global scope of the script:

The AngelScript engine is probably assuming that you are attempting to define a method within the class due to the parentheses, and so yields that error since methods have almost identical syntax.

(04-14-2012, 09:27 PM)Homicide13 Wrote: Also also, are classes considered "object" variables? I'm not quite sure on this one.

An object is just an instance of a class. To say that a class is an object variable is to form a paradox.

Tutorials: From Noob to Pro
04-14-2012, 11:38 PM
Website Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
#57
RE: [CHALLENGE THREAD]

So classes are normally defined within .h (header) files, the file that defines the class methods is the .lib (library) file (maybe?), and the file that actually makes use of the class members is the main.cpp source file (or I guess any of the source files? o.o)?

Then when you write up main.cpp, you would #include the .h file, and then continue to use the functions defined in the classes in the .h file which you included.

maybe something like that?


Anyways, when you do start using classes in your script, you use them by created objects that use the classes as templates for their "settings" (or i guess arguments), and objects pretty much act like names for groups of variables (or I guess primitives, which includes functions and whatnot).

And normally this would be useful, because you can have the class and its members all be defined in a separate file from the file you're using to do things, but since you can't reference other files with hlp2 .hps files, you might as well just make global functions/variables that are smartly named. Unless of course you want to apply a templates of attributes to multiple different things, in which case the use of classes would at least be the most readable option.

04-15-2012, 12:24 AM
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
#58
RE: [CHALLENGE THREAD]

(04-15-2012, 12:24 AM)Homicide13 Wrote: So classes are normally defined within .h (header) files, the file that defines the class methods is the .lib (library) file (maybe?), and the file that actually makes use of the class members is the main.cpp source file (or I guess any of the source files? o.o)?

Then when you write up main.cpp, you would #include the .h file, and then continue to use the functions defined in the classes in the .h file which you included.

maybe something like that?


Anyways, when you do start using classes in your script, you use them by created objects that use the classes as templates for their "settings" (or i guess arguments), and objects pretty much act like names for groups of variables (or I guess primitives, which includes functions and whatnot).

And normally this would be useful, because you can have the class and its members all be defined in a separate file from the file you're using to do things, but since you can't reference other files with hlp2 .hps files, you might as well just make global functions/variables that are smartly named. Unless of course you want to apply a templates of attributes to multiple different things, in which case the use of classes would at least be the most readable option.

Yes, you include the .h file. The other file is a mere .cpp file that holds the same name as the header file. It will auto link to it. You only do that to avoid giving unwanted information to the client.

The header file has the class's interface with the function prototypes, the other .cpp file contains the function definitions and the last contains the source code.

Templates wouldn't be the right word, but it's something like that. A class describes the object's atributes and functions.

Today I dreamt the life I could live forever. You only know that when you feel it for you know not what you like until you've experienced it.
(This post was last modified: 04-15-2012, 12:33 AM by nemesis567.)
04-15-2012, 12:30 AM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#59
RE: [CHALLENGE THREAD]

Why are we forcing use of classes in amnesia scripts anyway (Especially given that classes plus a robust system with saving and loading factored in with this game is not going to happen)? Surely a better idea for a challenge would be to give a set of design goals (a problem specification), a reasonable timeframe (a week or two), and let people implement them however they like?

(This post was last modified: 04-15-2012, 12:33 AM by Apjjm.)
04-15-2012, 12:32 AM
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
#60
RE: [CHALLENGE THREAD]

Apjjm, if you want the next challenge is yours. I'm out of ideas.

Today I dreamt the life I could live forever. You only know that when you feel it for you know not what you like until you've experienced it.
04-15-2012, 12:34 AM
Find




Users browsing this thread: 2 Guest(s)