Quote:
Originally Posted by iDigzy
Hi, I recently started scripting GS2 and I have a few questions.
1. What are classes for, like difference between weapons?
2. What is the point of npc's option when you can add npc's in level editor? Is it the same?
3. For setting things for a player, for example the hat or head would the script be something like player.attr1 = "filename"?
4. Are there any "and" or "or" words that can be used in an if statement? For example, a script like
function onPlayerchats() {
if (player.chat = "hello") *could you put an "and" or an "or" comparison here?* {
player.chat = "hi"
}
|
Classes are used to minimize code reuse and helps improve debugging/maintenance of your code as you'd only have to edit the single class to apply the changes to every script that uses that class. For example, you could have a class that handles damage which could then be called from any weapon script when you need to cause damage to a player instead of rewriting that same code in every weapon script.
It would be player.attr[1] = "filename";
and is && and or is ||
For example:
PHP Code:
function onPlayerChats() {
if (player.chat == "hello" || player.chat == "bye") {
player.chat = "hi";
}
}
Also if you are checking a value is equal to something please use the == operator instead of =, Although both work in GS2 it is good practice to use == for equality and = for assignment.