Home

Diff for "LuaScript" (#1 -> #2)

< Go back to page history

55   "sublayer_width": 14,
66}) }}
77
8 Lua Script object, create your own objects by scripting them. To learn more about Lua scripting, just search Google for Lua.
9 
10 The standard Lua math library is available through the global 'math'. For example, `math.floor(x)` and `math.sin(a)`.
11 
12 For a full list of mathematical functions available, check out [the official Lua math documentation](http://www.lua.org/manual/5.2/manual.html#6.6).
13 
14 Below is a list of Principia-specific stuff.
 8Lua Script object, write Lua programs that can interact with and control the level.
 9
 10For more information about Lua scripting in Principia, see [[Principia Lua Scripting]]
 11
 12Below is a reference of the Principia-specific Lua API.
1513
1614[toc]
1715
18 # this
19 "this" is a reference to the script object itself. "this" is a **global** object.
20 
21 ## this:write()
 16# `this`
 17`this` is a reference to the unique LuaScript object itself. `this` is a **global** object.
 18
 19## `this:write()`
2220Added in **1.3**
2321
2422Writes the value to the given OUT-socket. Values will be clamped between 0.0 and 1.0.
 
2927this:write(socket_id, value)
3028```
3129
32 ## this:read()
 30## `this:read()`
3331Added in **1.3**
3432
3533Reads the value from the given IN-socket.
 
3836local value = this:read(socket_id)
3937```
4038
41 ## this:has_plug()
 39## `this:has_plug()`
4240Added in **1.5**
4341
4442Returns true if the given IN-socket has a plug attached to it.
 
4846```
4947
5048
51 ## this:write_frequency()
 49## `this:write_frequency()`
5250Added in **1.3.0.2**
5351
5452Writes the value to the given frequency. Values will be clamped between 0.0 and 1.0.
 
5957this:write_frequency(frequency, value)
6058```
6159
62 ## this:listen_on_frequency()
 60## `this:listen_on_frequency()`
6361Added in **1.4**
6462
6563Starts listening on the given frequency.**NOTE:** Must be called in the init-function.
 
6866this:listen_on_frequency(frequency)
6967```
7068
71 ## this:read_frequency()
 69## `this:read_frequency()`
7270Added in **1.4**
7371
7472Reads the value from the given frequency.
 
7977local value = this:read_frequency(frequency)
8078```
8179
82 ## this:first_run()
 80## `this:first_run()`
8381Added in **1.3.0.2**, deprecated since **1.5**
8482
8583Returns true if the current step is called in the first run.
 
9088end
9189```
9290
93 ## this:get_position()
 91## `this:get_position()`
9492Added in **1.3.0.2**
9593
9694Returns the position of the LuaScript object.
 
9997local wx, wy = this:get_position()
10098```
10199
102 ## this:get_id()
 100## `this:get_id()`
103101Added in **1.4**
104102
105103Returns the unique ID of the LuaScript object.
 
108106local id = this:get_id()
109107```
110108
111 ## this:get_resolution()
 109## `this:get_resolution()`
112110Added in **1.4**
113111
114112Returns the resolution Principia is currently running at.
 
117115local width, height = this:get_resolution()
118116```
119117
120 ## this:get_ratio()
121 Added in **1.4**
122 
123 Returns the current screen ratio (window_width/window_height).
 118## `this:get_ratio()`
 119Added in **1.4**
 120
 121Returns the current screen ratio as a fraction (`window_width / window_height`).
124122
125123```lua
126124local ratio = this:get_ratio()
127125```
128126
129 ## this:set_sprite_blending()
 127## `this:set_sprite_blending()`
130128Added in **1.3.0.2**
131129
132130Sets the current blending mode used for drawing sprites.
133 
134 Blend modes:
135 - 0 = 0ff
136 - 1 = Mode A
137 - 2 = Mode B
 131- `0` = 0ff
 132- `1` = Mode A
 133- `2` = Mode B
138134
139135```lua
140136this:set_sprite_blending(blend_mode)
141137```
142138
143 ## this:set_sprite_filtering()
 139## `this:set_sprite_filtering()`
144140Added in **1.3.0.2**
145141
146142Sets the current filter mode used for drawing sprites.
147 
148 Filter modes:
149 - 0 = Nearest
150 - 1 = Linear
 143- `0` = Nearest
 144- `1` = Linear
151145
152146```lua
153147this:set_sprite_filtering(filter_mode)
154148```
155149
156 ## this:set_sprite_texel()
 150## `this:set_sprite_texel()`
157151Added in **1.3.0.2**
158152
159153Sets the color of a sprite texel.
 
162156this:set_sprite_texel(x, y, r, g, b, a)
163157```
164158
165 ## this:clear_texels()
 159## `this:clear_texels()`
166160Added in **1.4**, latest update **1.5**
167161
168162Clears all texels. From 1.5 it can now take a clear value. (0-255)
 
171165this:clear_texels(clear_value)
172166```
173167
174 ## this:set_draw_tint()
175 Added in **1.4**
176 
177 Sets the color for future sprite draws. (this:set_sprite_tint in 1.3.0.2)
 168## `this:set_draw_tint()`
 169Added in **1.4**
 170
 171Sets the color for future sprite draws. (`this:set_sprite_tint` in 1.3.0.2)
178172
179173```lua
180174this:set_draw_tint(r, g, b, a)
181175```
182176
183 ## this:set_draw_z()
184 Added in **1.4**
185 
186 Sets the Z-value for future sprite draws. (this:set_sprite_z in 1.3.0.2)
 177## `this:set_draw_z()`
 178Added in **1.4**
 179
 180Sets the Z-value for future sprite draws. (`this:set_sprite_z` in 1.3.0.2)
187181
188182```lua
189183this:set_draw_z(z_value)
190184```
191185
192 ## this:set_draw_coordinates()
 186## `this:set_draw_coordinates()`
193187Added in **1.5**
194188
195189Sets the coordinate mode any future sprite draws will use.
196 - 0 = World-based coordinates
197 - 1 = Screen-based coordinates (0,0 to 100,100)
198 - 2 = Local-based coordinates (Local to LuaScript-object by default, can be changed with the optional parameter local_id)
 190- `0` = World-based coordinates
 191- `1` = Screen-based coordinates (0,0 to 100,100)
 192- `2` = Local-based coordinates (Local to LuaScript-object by default, can be changed with the optional parameter local_id)
199193
200194```lua
201195this:set_draw_coordinates(coordinate_mode, local_id)
202196```
203197
204 ## this:draw_sprite()
 198## `this:draw_sprite()`
205199Added in **1.3.0.2**
206200
207201Draws a sprite with the given parameters.
 
210204this:draw_sprite(x, y, rotation, width, height, texel_from_x, texel_from_y, texel_to_x, texel_to_y)
211205```
212206
213 ## this:draw_line()
 207## `this:draw_line()`
214208Added in **1.4**
215209
216210Draws a line with the given parameters.
 
219213this:draw_line(x1, y1, x2, y2, width)
220214```
221215
222 ## this:draw_gradient_line()
223 Added in **1.5**
224 
225 Draws a gradient line with the given parameters. The color of the first point will be the one set in this:set_draw_tint(), and the second point will be the values given in the function parameters
 216## `this:draw_gradient_line()`
 217Added in **1.5**
 218
 219Draws a gradient line with the given parameters. The color of the first point will be the one set in `this:set_draw_tint()`, and the second point will be the values given in the function parameters.
226220
227221```lua
228222this:draw_gradient_line(x1, y1, x2, y2, width, r, g, b, a)
229223```
230224
231 ## this:draw_line_3d()
 225## `this:draw_line_3d()`
232226Added in **1.5**
233227
234228Draws a 3d line with the given parameters.
 
237231this:draw_line_3d(x1, y1, z1, x2, y2, z2, width)
238232```
239233
240 ## this:draw_gradient_line_3d()
241 Added in **1.5**
242 
243 Draws a 3d gradient line with the given parameters.The color of the first point will be the one set in this:set_draw_tint(), and the second point will be the values given in the function parameters
 234## `this:draw_gradient_line_3d()`
 235Added in **1.5**
 236
 237Draws a 3D gradient line with the given parameters. The color of the first point will be the one set in `this:set_draw_tint()`, and the second point will be the values given in the function parameters.
244238
245239```lua
246240this:draw_gradient_line_3d(x1, y1, z1, x2, y2, z2, width, r, g, b, a)
247241```
248242
249 ## this:get_sprite_texel()
 243## `this:get_sprite_texel()`
250244Added in **1.5**
251245
252246Returns the color for the given sprite texel.
 
255249local r, g, b, a = this:get_sprite_texel(x, y)
256250```
257251
258 ## this:init_draw()
 252## `this:init_draw()`
259253Added in **1.5**
260254
261255Initialized the drawing functionality for the current LuaScript object with the width and height specified.
262256- Minimum width or height: 1
263257- Maximum width or height: 1024
264 - Width and height MUST be power-of-two.
 258- Width and height MUST be a power-of-two.
265259
266260```lua
267261this:init_draw(width, height)
268262```
269263
270 ## this:set_static_sprite_texel()
271 Added in **1.5**
272 
273 Sets the color of a static sprite texel. X and Y must be within 0 and the (width/height)-1 specified in this:init_draw()
 264## `this:set_static_sprite_texel()`
 265Added in **1.5**
 266
 267Sets the color of a static sprite texel. X and Y must be within 0 and the (width/height)-1 specified in `this:init_draw()`.
274268
275269```lua
276270this:set_static_sprite_texel(x, y, r, g, b, a)
277271```
278272
279 ## this:clear_static_texels()
280 Added in **1.5**
281 
282 Clears all static texels to the given color. If no colors are specified, 0x7F will be set for all channels.
 273## `this:clear_static_texels()`
 274Added in **1.5**
 275
 276Clears all static texels to the given color. If no colors are specified, `0x7F` will be set for all channels.
283277
284278```lua
285279this:clear_static_texels(r, g, b, a)
286280```
287281
288 ## this:add_static_sprite()
 282## `this:add_static_sprite()`
289283Added in **1.5**
290284
291285Adds a sprite to be rendered with the given paramters. This only needs to be called once per sprite, because it will persist until this:clear_static_sprites() is called.
 
294288this:add_static_sprite(x, y, rotation, width, height, texel_from_x, texel_from_y, texel_to_x, texel_to_y)
295289```
296290
297 ## this:clear_static_sprites()
298 Added in **1.5**
299 
300 Removes all sprites that have been previously added with this:add_static_sprite()
 291## `this:clear_static_sprites()`
 292Added in **1.5**
 293
 294Removes all sprites that have been previously added with `this:add_static_sprite()`.
301295
302296```lua
303297this:clear_static_sprites()
304298```
305299
306 # game
307 a broad global object containing various *game*-stuff. game is a **global** object.
308 
309 ## game:show_numfeed()
 300# `game`
 301A global object containing various *game*-stuff. game is a **global** object.
 302
 303## `game:show_numfeed()`
310304Added in **1.3**, Latest update **1.3.0.3**
311305
312306Shows the given number on the screen for debugging.
313307
314 From **1.3.0.3** and onward, it can take the num_decimals argument which specifies with what precision the number should be printed.
 308From **1.3.0.3** and onward, it can take a `num_decimals` argument which specifies with what precision the number should be printed.
315309
316310```lua
317311local x, y = game:show_numfeed(number, num_decimals)
318312```
319313
320 ## game:finish()
321 Added in **1.3.0.2**
322 
323 Finish the game with the desired win state.
324 
325 - 1 = win
326 - 0 = lose.
 314## `game:finish()`
 315Added in **1.3.0.2**
 316
 317Finish the game with the desired win state:
 318- `1` = win
 319- `0` = lose
327320
328321```lua
329322game:finish(win_state)
330323```
331324
332 ## game:add_score()
 325## `game:add_score()`
333326Added in **1.3.0.2**
334327
335328Modifies the current score. Use a negative number to decrease the score.
 
338331game:add_score(score_mod)
339332```
340333
341 ## game:set_score()
 334## `game:set_score()`
342335Added in **1.3.0.2**
343336
344337Sets the current score.
 
347340game:set_score(new_score)
348341```
349342
350 ## game:get_score()
 343## `game:get_score()`
351344Added in **1.3.0.2**
352345
353346Returns the current score.
 
356349local score = game:get_score()
357350```
358351
359 ## game:activate_rc()
 352## `game:activate_rc()`
360353Added in **1.3.0.2**
361354
362355Activate RC Control of an entity using its object fetched with world:get_entity().
 
365358game:activate_rc(world:get_entity(entity_id))
366359```
367360
368 ## game:activate_rc_by_id()
 361## `game:activate_rc_by_id()`
369362Added in **1.3.0.2**
370363
371364Activate RC Control of an entity using its ID.
 
374367game:activate_rc_by_id(entity_id)
375368```
376369
377 ## game:message()
378 Added in **1.4**
379 
380 Outputs a message on the screen. Duration:
381 - 0 = Short
382 - 1 = Long.
 370## `game:message()`
 371Added in **1.4**
 372
 373Outputs a toast message on the screen. Duration:
 374- `0` = Short
 375- `1` = Long
383376
384377```lua
385378game:message(message, duration)
386379```
387380
388 ## game:get_cursor()
 381## `game:get_cursor()`
389382Added in **1.4**
390383
391384Gets the world coordinates for the cursor in the given layer.
 
394387local wx, wy = game:get_cursor(layer)
395388```
396389
397 ## game:poll_event()
398 Added in **1.4**
399 
400 Returns true if the given event just occured. [List of events](../World_Events)
 390## `game:poll_event()`
 391Added in **1.4**
 392
 393Returns true if the given event just occured. See [[Event Manager]] for event IDs.
401394
402395**NOTE:** This function should not be used any longer, and will be deprecated soon. Instead, use the on_event function.
403396
 
405398game:poll_event(event_id)
406399```
407400
408 ## game:get_screen_cursor()
 401## `game:get_screen_cursor()`
409402Added in **1.5**
410403
411404Get the cursor position on the screen. (Screen-based coordinates, based on the users screen resolution)
 
414407local x, y = game:get_screen_cursor()
415408```
416409
417 ## game:restart()
418 Added in **1.5**
419 
420 Restart the level
 410## `game:restart()`
 411Added in **1.5**
 412
 413Restart the level.
421414
422415```lua
423416game:restart()
424417```
425418
426 ## game:submit_score()
 419## `game:submit_score()`
427420Added in **1.5**
428421
429422Submits the player last saved score.
 
434427game:submit_score()
435428```
436429
437 ## game:set_variable()
438 Added in **1.5**
439 
440 Sets the value of the given variable.
 430## `game:set_variable()`
 431Added in **1.5**
 432
 433Sets the value of the given Principia variable.
441434
442435**NOTE**: Variables from Lua can contain values outside the normal 0.0-1.0 scope.
443436
 
445438game:set_variable(varname, value)
446439```
447440
448 ## game:get_variable()
 441## `game:get_variable()`
449442Added in **1.5**
450443
451444Gets the value of a variable.
 
456449local value = game:get_variable(varname)
457450```
458451
459 ## game:get_fps()
 452## `game:get_fps()`
460453Added in **1.5**
461454
462455Returns the average FPS.
 
465458local fps = game:get_fps()
466459```
467460
468 ## game:prompt()
 461## `game:prompt()`
469462Added in **1.5.1**
470463
471464Opens a [[Prompt]] with the given parameters.
 
481474The response function will only be called once, store the value if you wish.
482475
483476Valid responses:
484 - 1 = First button.
485 - 2 = Second button.
486 - 3 = Third button.
 477- `1` = First button.
 478- `2` = Second button.
 479- `3` = Third button.
487480
488481```lua
489482local prompt_id = game:prompt("Do you want to do something?", "Yes", "No", "Maybe!")
490483```
491484
492 # cam
493 controls the players camera. cam is a **global** object.
494 
495 ## cam:get_position()
 485# `cam`
 486Controls the player's camera. cam is a **global** object.
 487
 488## `cam:get_position()`
496489Added in **1.3**
497490
498491Returns the X, Y and Z coordinates of the camera.
 
501494local x, y, z = cam:get_position()
502495```
503496
504 ## cam:get_velocity()
 497## `cam:get_velocity()`
505498Added in **1.3**
506499
507500Returns the X, Y and Z velocity of the camera.
 
510503local x, y, z = cam:get_velocity()
511504```
512505
513 ## cam:set_position()
 506## `cam:set_position()`
514507Added in **1.3**
515508
516509Sets the position of the camera.
 
519512cam:set_position(x, y, z)
520513```
521514
522 ## cam:set_velocity()
 515## `cam:set_velocity()`
523516Added in **1.3**
524517
525518Sets the velocity of the camera.
 
528521cam:set_velocity(x, y, z)
529522```
530523
531 ## cam:follow_entity()
 524## `cam:follow_entity()`
532525Added in **1.3**
533526
534527Tells the game to follow the entity using the given properties.
 
537530cam:follow_entity(world:get_entity(entity_id), do_snap, preserve_position)
538531```
539532
540 ## cam:follow_entity_by_id()
 533## `cam:follow_entity_by_id()`
541534Added in **1.3**
542535
543536Tells the game to follow the entity using the given properties.
 
546539cam:follow_entity_by_id(entity_id, do_snap, preserve_position)
547540```
548541
549 ## cam:get_zoom_ratio()
550 Added in **1.5**
551 
552 Returns the fraction of the players current zoom. 0.0 being fully zoomed in, and 1.0 being fully zoomed out.
 542## `cam:get_zoom_ratio()`
 543Added in **1.5**
 544
 545Returns the fraction of the players current zoom. 0.0 being fully zoomed in, 1.0 fully zoomed out.
553546
554547```lua
555548local frac = cam:get_zoom_ratio()
556549```
557550
558 # world
559 world functions.world is a **global** object.
560 
561 ## world:get_entity()
 551# `world`
 552World functions. world is a **global** object.
 553
 554## `world:get_entity()`
562555Added in **1.3**, Latest update **1.5**.
563556
564 Returns an entity (object) reference or nil if the object does not exist.
565 
566 Renamed from world:get_entity_by_id() in 1.5.
 557Returns an entity (object) reference or `nil` if the object does not exist.
 558
 559Renamed from `world:get_entity_by_id()` in 1.5.
567560
568561```lua
569562local my_entity = world:get_entity(entity_id)
570563```
571564
572 ## world:raycast()
 565## `world:raycast()`
573566Added in **1.4**
574567
575568Raycasts from start to end. Returns nil if nothing was hit, otherwise returns the entity, ptx, pty, norx, nory.
 
578571local entity, ptx, pty, norx, nory = world:raycast(startx, starty, endx, endy, layer)
579572```
580573
581 ## world:query()
 574## `world:query()`
582575Added in **1.4**
583576
584577Returns a table of entities located within the given coordinates. Layers and sublayers are optional arguments.
 
587580local entities = world:query(min_x, min_y, max_x, max_y, layer, sublayers)
588581```
589582
590 ## world:get_gravity()
 583## `world:get_gravity()`
591584Added in **1.4**
592585
593586Returns the current X and Y gravity of the world.
 
596589local x, y = world:get_gravity()
597590```
598591
599 ## world:get_adventure_id()
600 Added in **1.5**
601 
602 Returns the ID that belongs to the Adventure robot.
 592## `world:get_adventure_id()`
 593Added in **1.5**
 594
 595Returns the ID that belongs to the Adventure Robot, if it exists.
603596
604597```lua
605598local id = world:get_adventure_id()
606599```
607600
608 ## world:get_borders()
 601## `world:get_borders()`
609602Added in **1.5**
610603
611604Returns the border sizes of the world.
 
614607local bup, bdown, bleft, bright = world:get_borders()
615608```
616609
617 ## world:get_world_point()
 610## `world:get_world_point()`
618611Added in **1.5**
619612
620613Converts a global screen point to a world point.
 
623616local wx, wy = world:get_world_point(gsx, gsy)
624617```
625618
626 ## world:set_bg_color()
627 Added in **1.5**
628 
629 Sets the BG color to the given values.
 619## `world:set_bg_color()`
 620Added in **1.5**
 621
 622Sets the background color to the given values.
630623
631624**NOTE:** Only works if you're using a colored background in the first place.
632625
 
634627world:set_bg_color(r, g, b)
635628```
636629
637 ## world:set_ambient_light()
 630## `world:set_ambient_light()`
638631Added in **1.5**
639632
640633Sets the ambient light of the world to the given value.
 
643636world:set_ambient_light(intensity)
644637```
645638
646 ## world:set_diffuse_light()
 639## `world:set_diffuse_light()`
647640Added in **1.5**
648641
649642Sets the diffuse light of the world to the given value.
 
652645world:set_diffuse_light(intensity)
653646```
654647
655 # Entity
 648# `Entity`
656649A reference to a Principia object.
657650
658 ## entity:get_id()
 651## `entity:get_id()`
659652Added in **1.3**
660653
661654Returns the unique ID of the current entity.
 
664657entity:get_id()
665658```
666659
667 ## entity:get_g_id()
 660## `entity:get_g_id()`
668661Added in **1.3**
669662
670663Returns the type ID of the current entity.
 
673666entity:get_g_id()
674667```
675668
676 ## entity:get_position()
 669## `entity:get_position()`
677670Added in **1.3**
678671
679672Returns the position of the current entity.
 
682675local x, y = entity:get_position()
683676```
684677
685 ## entity:get_angle()
 678## `entity:get_angle()`
686679Added in **1.3**
687680
688681Returns the angle of the current entity.
 
691684local angle = entity:get_angle()
692685```
693686
694 ## entity:get_velocity()
 687## `entity:get_velocity()`
695688Added in **1.3**
696689
697690Returns the linear velocity of the current entity.
 
700693local xvel, yvel = entity:get_velocity()
701694```
702695
703 ## entity:get_angular_velocity()
 696## `entity:get_angular_velocity()`
704697Added in **1.3**
705698
706699Returns the angular velocity of the current entity.
 
709702local avel = entity:get_angular_velocity()
710703```
711704
712 ## entity:get_bbox()
 705## `entity:get_bbox()`
713706Added in **1.3**
714707
715708Returns the approximate width and height of the object.
 
718711local width, height = entity:get_bbox()
719712```
720713
721 ## entity:get_layer()
 714## `entity:get_layer()`
722715Added in **1.4**
723716
724717Returns the layer of the current entity.
 
727720local layer = entity:get_layer()
728721```
729722
730 ## entity:local_to_world()
 723## `entity:local_to_world()`
731724Added in **1.4**
732725
733726Returns the world coordinates converted from the given local coordinates from the current entity.
 
736729local wx, wy = entity:local_to_world(lx, ly)
737730```
738731
739 ## entity:world_to_local()
 732## `entity:world_to_local()`
740733Added in **1.4**
741734
742735Returns the local coordinates converted from the given world coordinates in relation to the current entity.
 
745738local lx, ly = entity:world_to_local(wx, wy)
746739```
747740
748 ## entity:highlight()
 741## `entity:highlight()`
749742Added in **1.4**
750743
751744Highlight the entity.
 
754747entity:highlight()
755748```
756749
757 ## entity:damage()
 750## `entity:damage()`
758751Added in **1.5**
759752
760753Only works on destructible objects or creatures.
 
765758entity:damage(amount)
766759```
767760
768 ## entity:is_static()
 761## `entity:is_static()`
769762Added in **1.5**
770763
771764Returns true if the entity is a static object (unable to move), otherwise false.
 
776769end
777770```
778771
779 ## entity:absorb()
 772## `entity:absorb()`
780773Added in **1.5**
781774
782775Absorbs the entity if possible. The value returns indicates whether the absorb was completed successfully.
 
785778local success = entity:absorb(follow_connections)
786779```
787780
788 ## entity:apply_torque()
 781## `entity:apply_torque()`
789782Added in **1.5**
790783
791784Apply torque to the entity.
 
794787entity:apply_torque(torque)
795788```
796789
797 ## entity:set_velocity()
 790## `entity:set_velocity()`
798791Added in **1.5**
799792
800793Sets the linear velocity of the given entity.
 
803796entity:set_velocity(x, y)
804797```
805798
806 ## entity:warp()
 799## `entity:warp()`
807800Added in **1.5**
808801
809802Warps the entity to the given x/y world coordinates and layer. If the third argument is unset(layer), the layer will not be changed.
 
812805entity:warp(wx, wy, layer = -1)
813806```
814807
815 ## entity:show()
 808## `entity:show()`
816809Added in **1.5**
817810
818811Shows the entity if it was previously hidden.
 
821814entity:show()
822815```
823816
824 ## entity:hide()
 817## `entity:hide()`
825818Added in **1.5**
826819
827820Hides the entity if it was previously visible. It will still interact with the world even though it's hidden.
 
830823entity:hide()
831824```
832825
833 ## entity:get_name()
 826## `entity:get_name()`
834827Added in **1.5**
835828
836829Returns the name of the given entity.
 
839832local name = entity:get_name()
840833```
841834
842 ## entity:is_creature()
 835## `entity:is_creature()`
843836Added in **1.5**
844837
845838Returns true if the given entity is a creature.
 
850843end
851844```
852845
853 ## entity:is_robot()
 846## `entity:is_robot()`
854847Added in **1.5**
855848
856849Returns true if the given entity is any kind of robot.
 
861854end
862855```
863856
864 ## entity:is_player()
 857## `entity:is_player()`
865858Added in **1.5**
866859
867860Returns true if the given entity is the current player.
 
872865end
873866```
874867
875 ## entity:get_mass()
 868## `entity:get_mass()`
876869Added in **1.5**
877870
878871Returns the mass of the entity.
 
881874local mass = entity:get_mass()
882875```
883876
884 ## entity:get_density()
 877## `entity:get_density()`
885878Added in **1.5**
886879
887880Returns the average density of all fixtures of the given entity.
 
890883local density = entity:get_density()
891884```
892885
893 ## entity:get_friction()
 886## `entity:get_friction()`
894887Added in **1.5**
895888
896889Returns the average friction of all fixtures of the given entity.
 
899892local friction = entity:get_friction()
900893```
901894
902 ## entity:get_restitution()
 895## `entity:get_restitution()`
903896Added in **1.5**
904897
905898Returns the average restitution of all fixtures of the given entity.
 
908901local restitution = entity:get_restitution()
909902```
910903
911 ## entity:set_color()
 904## `entity:set_color()`
912905Added in **1.5**
913906
914907Sets the color of the given entity, if possible. Does not work will all entities.
 
919912entity:set_color(r, g, b)
920913```
921914
922 ## entity:disconnect_all()
 915## `entity:disconnect_all()`
923916Added in **1.5**
924917
925918Detach all connections from the entity.
 
928921entity:disconnect_all()
929922```
930923
931 ## entity:set_target_id()
 924## `entity:set_target_id()`
932925Added in **1.5**
933926
934927Sets the target ID of the given entity. Currently only usable with the robot manager.
 
937930entity:set_target_id(target_id)
938931```
939932
940 ## entity:call()
941 Added in **1.5**
942 
943 If the entity is a luascript object, call one of its functions.Example level: http://archive.principiagame.com/level/10140
 933## `entity:call()`
 934Added in **1.5**
 935
 936If the entity is a LuaScript object, call the specified function.
944937
945938```lua
946939local x, y = entity:call("my_ultracool_function", a, b, c)
947940```
948941
949 # Creature
950 A reference to a Principia creature. NOTE: Most entity-functions also work on creature, see creature as an extension to entity.
951 
952 ## creature:get_hp()
 942# `Creature`
 943A reference to a Principia creature.
 944
 945**NOTE:** Most entity-functions also work on creature, see creature as an extension to entity.
 946
 947## `creature:get_hp()`
953948Added in **1.5**
954949
955950Returns the HP and max HP of the creature.
 
958953local hp, max_hp = creature:get_hp()
959954```
960955
961 ## creature:get_armor()
 956## `creature:get_armor()`
962957Added in **1.5**
963958
964959Returns the armor and max armor of the creature.
 
967962local armor, max_armor = creature:get_armor()
968963```
969964
970 ## creature:get_aim()
971 Added in **1.5**
972 
973 Returns the aim of the current creature, assuming it can aim!
 965## `creature:get_aim()`
 966Added in **1.5**
 967
 968Returns the aim of the current creature, assuming it can aim.
974969
975970```lua
976971local aim = creature:get_aim()
977972```
978973
979 ## creature:set_aim()
 974## `creature:set_aim()`
980975Added in **1.5**
981976
982977Sets the weapon arm angle for the creature, if applicable.
 
985980creature:set_aim(new_aim)
986981```
987982
988 ## creature:stop()
989 Added in **1.5**
990 
991 Stop the creature from walking in the given direction. If no direction is given, the creature stops moving in all directions.left = -1, right = 1, down = 0, up = 2
 983## `creature:stop()`
 984Added in **1.5**
 985
 986Stop the creature from walking in the given direction. If no direction is given, the creature stops moving in all directions. (left = -1, right = 1, down = 0, up = 2)
992987
993988```lua
994989creature:stop(direction = all)
995990```
996991
997 ## creature:move()
998 Added in **1.5**
999 
1000 Tell the creature to start moving in the given direction.left = -1, right = 1, down = 0, up = 2
 992## `creature:move()`
 993Added in **1.5**
 994
 995Tell the creature to start moving in the given direction. (left = -1, right = 1, down = 0, up = 2)
1001996
1002997```lua
1003998creature:move(direction)
1004999```
10051000
1006 ## creature:is_action_active()
 1001## `creature:is_action_active()`
10071002Added in **1.5**
10081003
10091004Returns true if the creature has their special action activated.
 
10141009end
10151010```
10161011
1017 ## creature:action_on()
1018 Added in **1.5**
1019 
1020 Toggles the creatures special action on.
 1012## `creature:action_on()`
 1013Added in **1.5**
 1014
 1015Toggles the creature's special action on.
10211016
10221017```lua
10231018creature:action_on()
10241019```
10251020
1026 ## creature:action_off()
1027 Added in **1.5**
1028 
1029 Toggles the creatures special action off.
 1021## `creature:action_off()`
 1022Added in **1.5**
 1023
 1024Toggles the creature's special action off.
10301025
10311026```lua
10321027creature:action_off()