Skip to main content
Topic: DaVince's scripting tutorial (Read 61402 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

DaVince's scripting tutorial

For Sphere and/or JavaScript newbies: this tutorial is written for you guys! 8)

Here it is.

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. 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?

Re: DaVince's scripting tutorial

Reply #1
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.

Re: DaVince's scripting tutorial

Reply #2
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

 

Re: DaVince's scripting tutorial

Reply #3
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


Re: DaVince's scripting tutorial

Reply #4
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

Re: DaVince's scripting tutorial

Reply #5
Thanks  ;)