![]() |
Brief explanations about some new features: (NEW SCRIPT ENGINE)
For those of you who have a good programming experiance, don't bother reading this, this is just a simple thing I decided to type up to prepare those who have no programming experiance for some of the common things in programming languages that will now be in gscript, I aplogize for this being an easy tutorial but I don't really want anyone being confused about these simple things:
1. Function Params currently, the only way you can do functions in the current engine is by calling it like functionname(); and declaring it like function functionname() { //script } The new engine introduces a popular and great way to 'pass'/declare variables on a function, this is done by using the following: calling it: functionname("test",1,a); declaring it: function functionname(x,y,z){ //script } In the new engine, it gets rid of the need to use setstring to declare a string, you can just go var = "test"; now, so don't be confused by this: in the example stated before, it is the same as doing in the current engine x = "test"; y = 1; z = a; functionname(); as you can see this is a much more efficent and shorter way to pass/declare variables on a function 2. Declaring a Variable using a Function what I am talking about, is doing var = functionname(); Currently you cannot do that, this is an example of using it: NPC Code: The command/function 'return' is used to set the variable calling the function, yes I know right now it is return; you can also use return var; but in the new engine, most of the current commands are converted into functions 3. Switch Statements these are another way to do else-if statements, some people prefer to use these as they can look neater, example: NPC Code: this could be considered the equivilent of NPC Code: personally, I think the switch statement looks neater the way to start them out is by going switch (varname) { } Please don't ask why I chose to use @, I will explain that on a tutorial explaining some of the new engine's features later. after that, you can add cases, a case, such as case "test": is basically like if (varname == "test") if the case is true, it will run all the scripts under it until it reaches the break; command (break(); will work too I believe, I am just using break; for the sake of being less confusing) also, as you have noticed, I used something that wasn't considered a case, I used default: default is basically used when the var isn't equal to any of the cases above it, so it will execute the commands under default: until it finds a break; this is optional so don't feel like you need to include it 4. do-while loops these are really similar to while loops, with one difference which I will explain later NPC Code: now you may ask, why not just do NPC Code: The main difference between while and do-while loops, is that it will execute at least once before it checks the while condition, if the while condition is true, it will continue to do the loop. 5. More Operators Post and Pre increment / decrement post: var = n++; this is basically a short way to do var = n; n++; var = ++n; this is basically a short way or doing n++; var = n; same goes for decrement (--) Modulus Assignment a %= b Power Assignment a ^= b 6. Multi Dimention Arrays An example: a = b[0][1]; c = b[1][0]; one way you can construct 'b' is by doing b = {{0,1},{2,3}}; if b was the array in the previous example, a would become 1, c would become 2 there are no limits to how many dimentions you can use, but I really don't see any need to go beyond 3d arrays 7. for loop addition: I don't really know how to name this, but it is the way java does it, and it is the same as php's foreach (a as b) except in gscript, it is for (b: a) example: NPC Code: yes, that was a poor example, but a more practical use would be say... for(player: allplayers){ ... which is used on the playerlist script (allplayers can be accessed but not written to clientside) what it is doing, is taking each instance of the array a, and assigning it as the value b, it can be the equivilent of NPC Code: I may have forgotten some of the new features that are in other coding languages, but if I remember them, I will modify this post to add it, I apologize in advanced for how bad this tutorial was, I admit I kind of lost motivation near the end but I hope it helps :) comments and critisism is welcome (constructive only please) EDIT: made the for(var: array) explanation more clear |
The new commands are so C-ish.
|
Neato.
|
Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)
Quote:
Quote:
NPC Code: |
Thanks Jagen,that help alot.
|
Re: Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)
Quote:
just for (a: b); that's what I got from it, I haven't seen a few of these types of features before, thanks Jagen ;) |
Re: Re: Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)
Quote:
foreach(array as var) for each element in array, it will set the single element as var, and continue on in the loop until there are no more elements to declare 'var' as and cheetos, yes your example would work |
Re: Re: Re: Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)
Quote:
foreach $var (@somearray) { Or, if you use strict (which is far superior to normal perl in terms of coding, because it forces you to code more efficiently, and even helps you locate bugs more quickly) and have not declared the variable yet: foreach my $var (@somearray) { |
Ruby owns, though.
some_array.each { |some_array_member| # dostuffhere } |
I hope there'll be a replacestr. Like the replacestr in PHP. It'd make some things a little easier to do...
|
Perhaps I will find some time to write-up a brief doc that explains a few things with obj.function(). The stuff is really nice though, you guys will like it I'm sure =D
Most commands are translated to function, like addtiledef is now addtiledef() and realtext needs to be in quotations. ---Shifter |
Awsome, I always wanted GScript to have the capability of functions being able to return data.
|
1 Attachment(s)
Why doesn't someone update the NPC Scripting Document.
|
Quote:
Becouse there isn't one dedicated tutorial maker among us. |
Actually, I was making a tutorial, then the new engine starts to emerge c.c... and all the damn GST start to pop up having indepth info via Stefan giving them things. :(.. Mah. :(.. I cancelled my old tutorial, and now I await 3.1 for public realease to continue with a new tutorial.
And no, it's not one of them "here's all the commands, now you know them, go away" tutorials. I'm going to do it more of an 'example' tutorial, adding how to's for all the sorts of things that people ask. :) Though I will do command listing + examples, for reference. |
All times are GMT +2. The time now is 03:47 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.