LuaAPI.wiki
changeset 415 70961d4eef05
parent 414 14ec7b5cb560
child 416 5aa55bbe4b73
equal deleted inserted replaced
414:14ec7b5cb560 415:70961d4eef05
   294 
   294 
   295 == Functions for creating gears ==
   295 == Functions for creating gears ==
   296 
   296 
   297 === <tt>!AddGear(x, y, gearType, state, dx, dy, timer)</tt> ===
   297 === <tt>!AddGear(x, y, gearType, state, dx, dy, timer)</tt> ===
   298 
   298 
   299 <blockquote>This creates a new gear at position x,y (measured from top left) of kind gearType (see [GearTypes Gear Types]). The initial velocities are dx and dy. All arguments are numbers. The function returns the uid of the gear created.
   299 <blockquote>This creates a new gear at position x,y (measured from top left) of kind gearType (see [GearTypes Gear Types]). The initial velocities are dx and dy. All arguments are numbers. The function returns the uid of the gear created. Gears can have multple states at once: `state` is a bitmask, the flag variables can be found in [States].
   300 </blockquote>
   300 </blockquote>
   301 Example:
   301 Example:
   302 
   302 
   303 <code lang="lua">    local gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
   303 <code lang="lua">    local gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
   304     FindPlace(gear, true, 0, LAND_WIDTH)</code>
   304     FindPlace(gear, true, 0, LAND_WIDTH)</code>
   431 
   431 
   432 <blockquote>returns y coordinate of the gear
   432 <blockquote>returns y coordinate of the gear
   433 </blockquote>
   433 </blockquote>
   434 === <tt>!GetState(gearUid)</tt> ===
   434 === <tt>!GetState(gearUid)</tt> ===
   435 
   435 
   436 <blockquote>returns the state of the gear. This is one of [States]
   436 Returns the state of the gear. The gear state is a bitmask which is built out of the variables as shown in [States].
   437 </blockquote>
   437 
       
   438 This function is usually used in combination with `band` to extract the truth value of a single flag. It is also used together with `SetState` and `bor` in order to activate a single flag.
       
   439 
       
   440 Examples:
       
   441 <code language="lua">
       
   442 local state = GetState(gear)
       
   443 --[[ Stores the full raw bitmask of gear in state. Usually
       
   444 useless on its own. ]]
       
   445 </code>
       
   446 
       
   447 <code language="lua">
       
   448 isDrowning = band(GetState(CurrentHedgehog),gstDrowning) ~= 0
       
   449 --[[ GetState(CurrentHedgehog) returns the state bitmask of
       
   450 CurrentHedgehog, gstDrowning is a bitmask where only the
       
   451 “drowning” bit is set. band does a bitwise AND on both, if
       
   452 it returns a non-zero value, the hedgehog is drowning.]]
       
   453 </code>
       
   454 
       
   455 <code language="lua">
       
   456 SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstInvisible))
       
   457 --[[ first the state bitmask of CurrentHedgehog is bitwise ORed with
       
   458 the gstInvisible flag, thus making the bit responsible for
       
   459 invisiblity to become 1. Then the new bitmask is applied to
       
   460 CurrentHedgehog, thus making it invisible.]]
       
   461 </code>
       
   462 
       
   463 
   438 === <tt>!GetGearMessage(gearUid)</tt> ===
   464 === <tt>!GetGearMessage(gearUid)</tt> ===
   439 
   465 
   440 <blockquote>returns the message of the gear.
   466 <blockquote>returns the message of the gear.
   441 </blockquote>
   467 </blockquote>
   442 === <tt>!GetFollowGear()</tt> ===
   468 === <tt>!GetFollowGear()</tt> ===
   650 
   676 
   651 <blockquote>Sets the x and y coordinate of target-based weapons/utilities. <b> Note: </b>: This can't be used in onGearAdd() but must be called after gear creation. 
   677 <blockquote>Sets the x and y coordinate of target-based weapons/utilities. <b> Note: </b>: This can't be used in onGearAdd() but must be called after gear creation. 
   652 </blockquote>
   678 </blockquote>
   653 === <tt>!SetState(gearUid, state)</tt> ===
   679 === <tt>!SetState(gearUid, state)</tt> ===
   654 
   680 
   655 <blockquote>Sets the state of the specified gear to one of [States].
   681 Sets the state of the specified gear to the specified `state`. This is a bitmask made out of the variables as seen in [States].
   656 </blockquote>
   682 
       
   683 This function is often used together with `GetState` and the bitmask utility functions `band` and `bnot` in order to manipulate a single flag.
       
   684 
       
   685 Examples:
       
   686 <code language="lua">
       
   687 SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstInvisible))
       
   688 --[[ first the state bitmask of CurrentHedgehog is bitwise ORed with
       
   689 the gstInvisible flag, thus making the bit responsible for
       
   690 invisiblity to become 1. Then the new bitmask is applied to
       
   691 CurrentHedgehog, thus making it invisible. ]]
       
   692 </code>
       
   693 
       
   694 <code language="lua">
       
   695 SetState(CurrentHedgehog, band(GetState(CurrentHedgehog), bnot(gstInvisible)))
       
   696 --[[ The reverse of the above: This function toggles CurrentHedgehog’s
       
   697 gstInvisible flag off, thus making it visible again. ]]
       
   698 </code>
   657 
   699 
   658 === <tt>!SetGearMessage(gearUid, message)</tt> ===
   700 === <tt>!SetGearMessage(gearUid, message)</tt> ===
   659 
   701 
   660 <blockquote>Sets the message of the specified gear.
   702 <blockquote>Sets the message of the specified gear.
   661 </blockquote>
   703 </blockquote>