What is a "Snippet" ?

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,486
Reaction score
227
Location
( ͡° ͜ʖ ͡°)
Re: Snippet

Snippet is a programming term for a small region of re-usable source code, machine code, or text. Ordinarily, these are formally-defined operative units to incorporate into larger programming modules. Snippets are often used to clarify the meaning of an otherwise "cluttered" function, or to minimize the use of repeated code that is common to other functions. The snippets themselves may be either literal text, or written in a simple template language to allow substitutions, such as variable names. Snippets are a small-scale form of copy and paste programming. Snippet management is a feature of some text editors, program source code editors, IDEs, and related software. It allows the user to persist and use snippets in the course of routine edit operations.

http://en.wikipedia.org/wiki/Snippet_(programming)
 

xzytro

God
Joined
Apr 1, 2013
Messages
2,294
Reaction score
7
Re: Snippet

Well... While i was explaining this, opcode just replied with copy&paste. Still, i will post this just in case you want an explanation in an easier english with a lower level.

A snippet is, a group of codes which can be inserted inside a script to get additional functions running. A snippet is not a script, and it can not work on it's own. It needs to be implemented inside a coded project in order to complete the script faster.

Although snippets are useful for the coders to complete their scripts, they are not helpful on their own for the users themselves, as they exist only in purpose of defining some needed elements for the coders. Here's an example of a snippet for cleo scripts :

Code:
{$CLEO .cs}
THREAD "AIM_EXPLOSION"
0662: NOP "www.youtube.com/OpcodeXe" 
0662: NOP "www.ugbase.eu" 

:START
wait 10
if
0AB0: KEY_PRESSING: 2 // RIGHT MOUSE BUTTON - AIMING
jf @START
GOSUB @GET_AIMING_POS // RETURNS AIMING AT POSITION TO: 0@ 1@ 2@
020C: create_explosion_with_radius 3 at 0@ 1@ 2@ 
Jump @START




:GET_AIMING_POS // PASTE THIS AT THE END OF THE SCRIPT
Actor.StorePos($PLAYER_ACTOR, 1@, 2@, 3@)
0A9F: 5@ = current_thread_pointer 
5@ += 80 
0A8E: 6@ = 5@ + 12 // int 
0AA6: call_method 5327216 11989032 num_params 6 pop 0 6@ 5@ 3@ 2@ 1@ 4@  
if 
86BD:   not no_obstacles_between 1@ 2@ 3@ and 8@ 9@ 10@ solid 1 car 1 actor 0 object 1 particle 0 
else_jump @ADD 
jump @END_POS 

:ADD
4@ += 1.0 
if
  4@ > 250.0 
else_jump @GET_AIMING_POS 

:END_POS
0@ = 0.0
1@ = 0.0
2@ = 0.0
005B: 0@ += 8@ // (float) 
005B: 1@ += 9@ // (float) 
005B: 2@ += 10@ // (float)
4@ = 0.0 // RESET THE AIM RADIUS  
return

This snippet defines the position of aiming point. Without this snippet, you might lose your time on trying to make something that will define the positions of aiming point. But with existence of it's snippet, you can gain time & complete your script much faster and with less doubts.
 
Top