Graalians

Graalians (https://www.graalians.com/forums/index.php)
-   Creative Corner (https://www.graalians.com/forums/forumdisplay.php?f=17)
-   -   John's Scripts (https://www.graalians.com/forums/showthread.php?t=9528)

Tricxta 09-09-2012 10:53 PM

Quote:

Posted by xXziroXx (Post 195563)
Being used to doing something in one way is a poor excuse for not needing to change. There's no need to be so defensive, I was trying to give you some pointers, that's all. John is trying to learn GScript, if you should ever lead by a good example, this is as good of a time as it gets.

I was demonstrating a method, not good coding conventions. But yer, you have your valid points. Keep up the good work master c0dur.

Johnaudi 09-10-2012 06:39 AM

Thanks guys :)
Now I simply want to know, what's the usage of "?"...
Like 3 ? 2 = ?
Just wanted to learn that as I see it in several scripts.

Tricxta 09-10-2012 10:02 AM

Quote:

Posted by Johnaudi (Post 195767)
Thanks guys :)
Now I simply want to know, what's the usage of "?"...
Like 3 ? 2 = ?
Just wanted to learn that as I see it in several scripts.

It's a conditional statement.
PHP Code:

variable = (condition)?x:y

is equivalent to
PHP Code:

if (condtion)
  
variable x;
else
  
variable y

Some people think they're pretty ugly. I only use them if it's a small statement otherwise I stretch it out for viewing purposes. Also makes debugging that much easier.

callimuc 09-10-2012 07:50 PM

another example (just have to put my contribution :P)

PHP Code:

temp.flag true;
player.chat "The statement is: " @ (temp.flag "true :D" "false :("); 


Johnaudi 09-10-2012 09:09 PM

I don't exactly get it since, let's say we have :
temp.var = 5;
player.chat = "Number"SPC (temp.var ? "is correct" : "is false");

I don't see how they can know that it's "if (temp.var == 5)" or not == 4. Is it used for booleans only? (true / false)?

xXziroXx 09-10-2012 10:07 PM

Quote:

Posted by Johnaudi (Post 195962)
I don't exactly get it since, let's say we have :
temp.var = 5;
player.chat = "Number"SPC (temp.var ? "is correct" : "is false");

I don't see how they can know that it's "if (temp.var == 5)" or not == 4. Is it used for booleans only? (true / false)?

In your case, you'd do (temp.var == 5 ? "is correct" : "is false")

callimuc 09-10-2012 11:28 PM

Quote:

Posted by Johnaudi (Post 195962)
I don't exactly get it since, let's say we have :
temp.var = 5;
player.chat = "Number"SPC (temp.var ? "is correct" : "is false");

I don't see how they can know that it's "if (temp.var == 5)" or not == 4. Is it used for booleans only? (true / false)?

as tricxta said, its
PHP Code:

(condition condition_true condition_false); 

just like
PHP Code:

if (condition) {
  
condition_is_true_stuff;
}
else {
  
condition_is_false_stuff;


the condition can be just like in if() checks. so you can go from if (something_is_true/false) ...., if (something == something else) ...., if (something != something else) ...., ... . its good to use the ? if you got short checks or want to call functions, like

PHP Code:

temp.number 5;
player.chat "the number is 5? " @ (temp.number == "yes!" "no!");

//instead of

temp.number 5;
if (
temp.number == 5player.chat "the number is 5? yes!";
else 
player.chat "the number is 5? no!"



//or



temp.invalid_speed true;
temp.invalid_speed speedFix() : anotherFunction();

//instead of

temp.invalid_speed true;
if (
temp.invalid_speedspeedFix();
else 
anotherFunction(); 


Johnaudi 09-11-2012 07:35 AM

Quote:

Posted by xXziroXx (Post 195986)
In your case, you'd do (temp.var == 5 ? "is correct" : "is false")

Cleared everything up you and Callimuc :) thanks again.
hm so let's see what's left to know, anyone got an idea?

callimuc 09-11-2012 06:03 PM

best way is to test around, look at other scripts and so on

Johnaudi 09-11-2012 07:57 PM

Oh yes, vecx and vecy please, I didn't get a clue of what they are about. Thanks!

Emera 09-11-2012 08:10 PM

If you're up for a spot of reading, Tigairius made an in-depth explanation on vecx and vecy on the official forums. You should check it out.

Johnaudi 09-11-2012 09:55 PM

Thanks @ Emera, understood it, but how exactly and where to use it :/

xXziroXx 09-12-2012 02:13 AM

If you have a PC account that has had Gold at least once, I highly recommend that you register on those forums with it. The scripting help you can get there is likely to be overwhelmingly more (and arguably better) than here.

Emera 09-12-2012 08:03 AM

Quote:

Posted by xXziroXx (Post 196557)
If you have a PC account that has had Gold at least once, I highly recommend that you register on those forums with it. The scripting help you can get there is likely to be overwhelmingly more (and arguably better) than here.

Ziro's right. As much as we'd all love to help you, there's only so far we can go. I'm not the best of scripters, and there's going to be a point sooner or later where I'm going to start struggling answering your questions, and the few who are helping you won't be far behind me on that one. If you're unable to buy gold yourself, I'll happily buy you a month of it so you're able to sign up to those forums.

Jester Lapse 09-12-2012 09:00 AM

Quote:

Posted by Emera (Post 196688)

Ziro's right. As much as we'd all love to help you, there's only so far we can go. I'm not the best of scripters, and there's going to be a point sooner or later where I'm going to start struggling answering your questions, and the few who are helping you won't be far behind me on that one. If you're unable to buy gold yourself, I'll happily buy you a month of it so you're able to sign up to those forums.

He works iEra so he gets free gold. Pay for mine nub <3_<3


All times are GMT. The time now is 10:31 AM.

Powered by vBulletin/Copyright ©2000 - 2025, vBulletin Solutions Inc.