Spherical forums

User-Made => Articles => Topic started by: DaVince on July 06, 2013, 07:33:13 am

Title: DaVince's scripting tutorial
Post by: DaVince on July 06, 2013, 07:33:13 am
For Sphere and/or JavaScript newbies: this tutorial is written for you guys! 8)

Here it is (http://wiki.spheredev.org/DaVince_scripting_tutorial).

I improved it. Well, most of it. I rewrote some sections and a bunch of sentences so it's hopefully more clear and accurate than before. I formatted some examples and other stuff.

Also, I got off my lazy ass and wrote the tutorial on objects (http://wiki.spheredev.org/DaVince_scripting_tutorial#Objects). I tried taking an approach where an example is followed. It only teaches the basics, but the basics should be good enough for this tutorial. Could anyone read through it and see if I haven't made any dumb mistakes (or suggest improvements)? Some stuff I should really, really add?
Title: Re: DaVince's scripting tutorial
Post by: Xenso on July 06, 2013, 11:38:27 am
Its really neat and well organized 8)
Thanks, I know its a mini-bible of text to edit. I'm sure this will be of help to newbies, I know I learned a lot especially from the objects and variables which where more clear to see and understand.
Title: Re: DaVince's scripting tutorial
Post by: DaVince on July 06, 2013, 12:24:05 pm
That's good to know!

And I've working on trimming things so it's less Bible-like. It's still a lot of text. :P
Title: Re: DaVince's scripting tutorial
Post by: Xenso on July 06, 2013, 12:44:44 pm
One question though

Code: [Select]

this.unequip = function(what)
{
  var theitem = all_equipment_ever[what];          //Get the item
  var itemindex = this.equipment.indexOf(theitem); //Get the numerical position of the item in the array
  this.equipment.splice(itemindex, 1);             //Remove the item from the array
}


what is the 1 for?
Code: [Select]

  this.equipment.splice(itemindex, 1);  //Remove the item from the array

Title: Re: DaVince's scripting tutorial
Post by: DaVince on July 06, 2013, 12:54:14 pm
Good question! I didn't explain Array.splice at all, kind of on purpose, in order to make you look it up yourself. :P

It defines how many elements to remove in the array from the given index onward. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
Title: Re: DaVince's scripting tutorial
Post by: Xenso on July 07, 2013, 02:28:57 am
Thanks  ;)