http://guide.swcombine.com/api.php?action=feedcontributions&user=Ruben+Wan&feedformat=atomStar Wars Combine :: Game Guide - User contributions [en]2024-03-29T16:02:44ZUser contributionsMediaWiki 1.31.0-rc.0http://guide.swcombine.com/index.php?title=XP&diff=3805XP2019-02-02T12:08:38Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 30 XP with the following message: You hired an NPC for the first time.<br />
*You gained 20 XP with the following message: You used an item for the first time.<br />
*You gained 20 XP with the following message: You have joined chat for the first time.<br />
*You gained 20 XP with the following message: You have made your first post on the forums. (SWC forums)<br />
*You gained 40 XP with the following message: You learned how to build a facility.<br />
*You gained 10 XP with the following message: You found out how to form a party.<br />
*You gained 40 XP with the following message: You now know how to use scanners.<br />
*You gained 10 XP with the following message: You walked to another room for the first time.<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3804XP2019-01-11T12:04:07Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 20 XP with the following message: You used an item for the first time.<br />
*You gained 20 XP with the following message: You have joined chat for the first time.<br />
*You gained 20 XP with the following message: You have made your first post on the forums. (SWC forums)<br />
*You gained 40 XP with the following message: You learned how to build a facility.<br />
*You gained 10 XP with the following message: You found out how to form a party.<br />
*You gained 40 XP with the following message: You now know how to use scanners.<br />
*You gained 10 XP with the following message: You walked to another room for the first time.<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Trading&diff=3803Trading2018-12-26T01:03:17Z<p>Ruben Wan: /* Prices and Markets */</p>
<hr />
<div>==How Does Trading Work? ==<br />
===Trading=== <br />
'''Important things to keep in mind:'''<br /><br />
In the Combine, stealing from players through trading is an acceptable In Character action and is, therefore, neither punished nor undone. As such, it is strongly advised that traders not send first to others they do not already trust. If you doubt the honesty of the other party, then use a respected middleman. If you aren't sure who to trust, the best thing to do is to consult established Trader Reputation lists or by asking someone in your faction. If you have IRC access, you may also consider asking around in the #SWC-Traders channel on irc.swc-irc.com (See IRC section below). <br />
<br />
'''Known Scammers''' <br /><br />
An up to date listing of known scammers, located in the Traders Lounge and compiled from the reports of traders posted in the forum. <br />
http://www.swcombine.com/forum/thread.php?thread=9177&page=0 <br />
<br />
The idea behind trading is to buy and sell ships, vehicles, cities, buildings, and other assets in order to make a profit. At this time, most trading takes part in the IRC trading channel, in the Combine's RPG Centre forums, and on some private markets run by various factions. When visiting #SWC-Traders on IRC, you will see people using the following abbreviations: <br />
<br />
'''WFS''' - What's for sale? <br /><br />
This is asking the traders in the room what they are selling. <br />
<br />
'''FS''' - For sale <br /><br />
When you are trying to sell something, you would add FS as the start then the type of ships (e.g. FS: YT-1300, 2 Firesprays). <br />
<br />
'''FT''' - For trade <br /><br />
This means someone has a ship they wish to trade for another type of ship (e.g. FT: YT-510). <br />
<br />
'''FA''' - For auction <br /><br />
When something is for auction, normally the trader auctioning the item off will provide a link to the auction listing, or it will be online in another channel (e.g. FA: Carrack Cruiser - come to #my_room to bid). <br />
<br />
'''OBO''' - Or Best Offer <br /><br />
When the seller states a price he/she could also accept other offers (e.g. BFF-1 bulk freighter, 21 millions OBO).<br />
<br />
'''WTB''' - Want to Buy <br /><br />
When looking to buy a specific item, use this (e.g. WTB: Y-Wing). <br />
<br />
'''WTS''' - Want to Sell <br /><br />
When looking to sell a specific item, use this (e.g. WTS: X-Wing).<br />
<br />
'''U/U/U''' - Undamaged, Undocked, Unshielded <br /><br />
The entity is not under shield or inside another entity, and its stats are all topped.<br />
<br />
When selling a ship, you may be asked to assign the ship first before making it over, and it is recommended that you ask the same of a seller if you are looking to buy a ship, if you have any doubts that they own it. Always avoid sending first to traders you do not trust, or are not listed as reputable. If the other party refuses to send first or to use a middleman, there is a high likelihood that they are trying to steal from you.<br />
<br />
===Prices and Markets=== <br />
<br />
The Combine has an official market built into its interface, accessed through the '[[Galactic Market|Market]]' link on the right-hand menu (or through http://www.swcombine.com/members/market/ directly). To buy from or sell to the market, you must be on a trading station or inside a commerce centre facility. In case your faction cannot provide you access to such a facility, the factions Centrepoint Space Station and Baobab Merchant Fleet host a listing of public trading stations at http://www.centrepointstation.com/services/markets.php and http://bmf.force501.com/forum/viewtopic.php?f=104&t=2787 respectively. It is best to purchase items as close to your location as possible, since the closer you are to the item you are buying, the less it will cost you. When you purchase it from the market, it is made over to you immediately. Not many traders sell to this market as doing so is not very profitable, so the majority of assets available at any given time are usually the former possessions of a character that has recently died. <br />
<br />
The Centrepoint Space Station trading faction also hosts a private market on its own website (referred to as Centrepoint Market, or CPM, and located at http://market.centrepointstation.com/), and this is what most traders use. This market can be compared to eBay, in that traders can post listings for items they are selling and other traders can bid on them or buy them out, but the items are not transferred immediately. The traders must contact each other to complete the transaction, and it is strongly recommended that a trusted middleman is used. This offsite market (linked in Useful Links below) is not officially affiliated with the Combine, and as such, any problems with it need to be directed to the faction hosting it. <br />
<br />
The Trade Federation Market (aka TFM) is another place where individuals and companies can advertise their goods (http://dot.swc-tf.com/index.php).<br />
<br />
The prices listed in the rules section of the Combine's website are only the raw production cost of each item. This is bound to be a much lower price than you will be able to purchase the items for from other players. Prices are constantly changing depending on how desirable the item in question is, how many are available to the public, and how much sellers are willing to sell for. Faction-specific items, such as TIE Fighters and A-Wings, are generally not available to the public. In the rare instance that some are successfully stolen from their faction, they tend to sell for hundreds of millions of credits.<br />
<br />
===Useful Links=== <br />
<br />
'''Centrepoint Market '''<br />
http://market.centrepointstation.com/ <br />
<br />
'''Trade Federation Market '''<br />
http://dot.swc-tf.com/index.php<br />
<br />
'''Traders Lounge''' ''(for trading discussion, not for buying/selling)'' <br />
http://www.swcombine.com/forum/forum.php?forumID=55 <br />
<br />
'''Commerce forum''' <br />
http://www.swcombine.com/forum/forum.php?forumID=52 <br />
<br />
'''Gambling Hut '''<br />
http://www.swcombine.com/forum/forum.php?forumID=139<br />
<br />
===IRC (Internet Relay Chat)=== <br />
<br />
[[IRC]] refers to online chatrooms, used to communicate with other individuals in real-time over the Internet. <br />
<br />
http://www.mirc.com <br />
mIRC is the preferred client for the Windows platform. This is recommended for users who plan to use IRC on a regular basis. <br />
<br />
http://www.swcombine.com/community/chat/ <br />
The Combine also hosts a Java client through which players can connect to the Combine IRC server directly through their web browser without downloading an alternate IRC client. This is recommended for users who will not be using IRC on a regular basis. <br />
<br />
Server: irc.swc-irc.com <br />
Port: 6667 <br />
<br />
'''Channels '''<br />
* #swc-members - SWC Members Room, for general chat with other players. <br />
* #swc-traders - SWC Trading Room, for buying and selling from other players. <br />
* #swc-help - SWC Help Room, for Combine-related and IRC-related help. <br />
* #CMG- is a prefix usually used to access a specific faction's chatroom.<br />
[[Category:Advanced Activities]]<br />
[[Category:Game Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3802XP2018-12-19T20:37:04Z<p>Ruben Wan: </p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 20 XP with the following message: You have joined chat for the first time.<br />
*You gained 20 XP with the following message: You have made your first post on the forums. (SWC forums)<br />
*You gained 40 XP with the following message: You learned how to build a facility.<br />
*You gained 10 XP with the following message: You found out how to form a party.<br />
*You gained 40 XP with the following message: You now know how to use scanners.<br />
*You gained 10 XP with the following message: You walked to another room for the first time.<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Medicine&diff=3801Medicine2018-12-06T21:56:55Z<p>Ruben Wan: /* Medical Items: What and How */</p>
<hr />
<div>== Medical Items: What and How ==<br />
<br />
[http://www.swcombine.com/rules/?Medical_Items Medical items] will let you restore your own, another player's or an NPC's [[HP]].<br />
They can be produced by any medical faction.<br />
<br />
The following items are considered medical items and can be used to restore HP:<br />
<br />
{| border="1" style="text-align:center;"<br />
|-<br />
| [[File:BactaPatch.png|center]][http://www.swcombine.com/rules/?Medical_Items&ID=107 Bacta Patch] || [[File:BactaRefill.png|center]][http://www.swcombine.com/rules/?Medical_Items&ID=114 Bacta Refill] || [[File:Emptybactatank.png|center]][http://www.swcombine.com/rules/?Medical_Items&ID=112 Bacta Tank] || [[File:HealingStick.png|center]][http://www.swcombine.com/rules/?Medical_Items&ID=111 Healing Stick] || [[File:KoltoPatch.png|center]][http://www.swcombine.com/rules/?Medical_Items&ID=399 Kolto Patch] || [[File:Medikit.png|center]] [http://www.swcombine.com/rules/?Medical_Items&ID=108 Medikit]<br />
|}<br />
<br />
To use a medical item, the following conditions must be met: <br />
<br />
*You and your target need to be at the same location.<br />
*You and your target must be in the same faction or be set as "Friend" on each other's IFF.<br />
*You and your target must not be part of another medical action.<br />
*For Bacta Tanks and Medikits: You need enough Bacta Refills inside the entity.<br />
*For Bacta Tanks: The Tank must be deployed in a medical room and you and your target must be in the same room.<br />
<br />
While being part of a medical action, neither you nor your target can move. Before being put into a Bacta Tank, the target automatically drops all equipped items.<br />
<br />
=== Drugs ===<br />
<br />
Trading factions may produce counterfeit medical items or drugs which look exactly like some medical items. These drugs are mainly made from Ryll and are cheaper to produce. However upon using them as a medical item, they result in 0 HP being recovered.<br />
<br />
=== Using a Medical Item ===<br />
<br />
To use a medical item on someone else, you have to apply it via the Item screen or - in case of the bacta tank - load the patient into the tank. After using a medical item, the following will happen to the medical item: <br />
*Bacta Patch / Ryll Patch / Kolto Patch: item is destroyed<br />
*Healing Stick / Death Stick: item is destroyed<br />
*Medikit: Medikit remains, 1 Bacta Refill / Ryfill inside is destroyed<br />
*Bacta Tank: Tank remains, all 3 Bacta Refills / Ryfills inside are destroyed<br />
<br />
=== Filling a Bacta Tank ===<br />
Bacta refills are loaded into the tank the same way one would load items into a container.<br />
*Click on a bacta refill.<br />
*The tank is now highlighted as a location where the item can be moved into.<br />
*Click on the tank.<br />
*Repeat the above two more times, until you have 3 refills in the tank.<br />
<br />
== Equations ==<br />
{| Border="1" style="text-align:center;"<br />
|-<br />
| '''Item''' || '''Base Amount Healed''' || '''Refills Needed''' || '''Time/min'''<br />
|- <br />
| Kolto Patch || 3 || N/A || 30<br />
|-<br />
| Bacta Patch || 5 || N/A || 30<br />
|-<br />
| Healing Stick || 8 || N/A || 30<br />
|-<br />
| Medikit with Bacta Refill || 10 || 1 || 30<br />
|-<br />
| Bacta Tank with Bacta Refill || All HP Restored|| 3 || 600&dagger;<br />
|-<br />
| Ryll Patch || 0 || N/A || 30 <br />
|-<br />
| Death Stick || 0 || N/A || 30<br />
|-<br />
| Medikit with Bacta Ryfill || 0 || 1 || 30<br />
|-<br />
| Bacta Tank with Bacta Ryfill || 0 || 3 || 600&dagger;<br />
|}<br />
&dagger;NOTE: For most medical items, both the player using the item (the "healer") and the player being healed will enter into a Medical Timer. However, for Bacta Tanks, only the player being healed receives a timer, leaving the "healer" free to go about other activities.<br />
<br />
<br />
The amount of HP restored depends on the item used and the user's Medical Skill as per the following formula: <br />
<br />
HP restored = round(Base Amount Healed × (Medical Skill + 1)) <br />
<br />
If the healing is done within a [[#Entities with Medical Rooms|medical entity]], the healing power of the medical items is increased by a factor of 1.3:<br />
<br />
HP restored = round(Base Amount Healed × (Medical Skill + 1) × 1.3) <br />
<br />
The XP gained from using medical items is:<br />
<br />
XP gained = round(HP restored / 2)<br />
<br />
=== Example 1 ===<br />
<br />
Veynom has 12 HP left of his maximum of 85 HP. He has a Medical Skill of 3. He applies a Bacta Patch to heal his wounds. <br />
<br />
HP restored = 5 * (3 + 1) = 20<br />
XP gained = 20 / 2 = 10<br />
<br />
=== Example 2 ===<br />
<br />
Selatos has 20 HP left of his maximum 100 HP. He has a Medical Skill of 5. He uses a Medikit with a Bacta Refill to heal his wounds.<br />
<br />
HP restored = 10 * (5 + 1) = 60<br />
XP gained = 60 / 2 = 30<br />
<br />
=== Bacta Tanks ===<br />
<br />
Bacta Tanks can only be deployed in medical rooms. For a bacta tank to be deployed, it must be inside a medical room and no other tanks can be deployed in the same room. (i.e., you can only deploy a single tank in a room).<br />
<br />
Once deployed, the tank can be loaded with up to three Bacta Refills. Once a single refill is loaded, the tank cannot be undeployed, nor can the refill be taken out again. You cannot load more than three refills.<br />
<br />
Once three refills have been loaded, you can apply the tank to a patient (either yourself, another player or an NPC in your party). At that time, the patient will drop all items he's carrying and is loaded into the tank. He will be ejected once the healing process is completed.<br />
<br />
Any player can add an unconscious player to their party, and a Bacta Tank can be used to heal them above 0 HP.<br />
<br />
Bacta Tanks can be flushed, removing any previously loaded Bacta Refills (or Bacta Ryfills) in the process. This can only be done if no patient is present in the tank.<br />
<br />
== Entities with Medical Rooms ==<br />
<br />
The following entities contain one or more medical rooms. <br />
<br />
*Facilities:<br />
Asylum (1), Command Centre (1), Conference Centre (1), Government House (1), Hospital (6), Imperial Palace (2), Palace (1), Praxium (1), Royal Hapan Palace (1), Sith Temple (1) <br />
<br />
*Ships:<br />
Ardent-class Fast Frigate (1), Battle Dragon (1), Darkstar-class Battleship (1), EF65 Meridian-class Frigate (2), EF76 Nebulon-B Medical Frigate (4), Executor-class Star Destroyer (1), Imperial I-class Star Destroyer (1), Ithorian Herdship (1), Lucrehulk-class Battleship (1), MC-80 Home One-class Star Cruiser (1), MC-80a Star Cruiser (1), MC-80b Star Cruiser (1), Prometheus-class Star Craft (2), Pulsar Battle Cruiser (1), Sprint-class Rescue Craft (2), Veltraa-class Cruiser (1), Verpine-class Heavy Cruiser (1)<br />
<br />
*Vehicles:<br />
Conquest-class Carrier (1), Kettrifee Air Mover (4)<br />
<br />
*Space Stations:<br />
Centrepoint Station (1), Jubilee Wheel (4), Hospital Platform XQ-2 (3), Medical Factory Station (1)<br />
[[Category:Advanced Activities]]<br />
[[Category:Game Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3800XP2018-11-29T18:55:49Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 20 XP with the following message: You have made your first post on the forums. (SWC forums)<br />
*You gained 40 XP with the following message: You learned how to build a facility.<br />
*You gained 10 XP with the following message: You found out how to form a party.<br />
*You gained 40 XP with the following message: You now know how to use scanners.<br />
*You gained 10 XP with the following message: You walked to another room for the first time.<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3799XP2018-11-26T19:02:58Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 40 XP with the following message: You learned how to build a facility.<br />
*You gained 10 XP with the following message: You found out how to form a party.<br />
*You gained 40 XP with the following message: You now know how to use scanners.<br />
*You gained 10 XP with the following message: You walked to another room for the first time.<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3798XP2018-11-24T02:07:49Z<p>Ruben Wan: </p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 10 XP with the following message: You found out how to form a party.<br />
*You gained 40 XP with the following message: You now know how to use scanners.<br />
*You gained 10 XP with the following message: You walked to another room for the first time.<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3797XP2018-11-24T00:12:32Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 40 XP with the following message: You now know how to use scanners.<br />
*You gained 10 XP with the following message: You walked to another room for the first time.<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3796XP2018-11-17T18:10:02Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 10 XP with the following message: You walked to another room for the first time.<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3795XP2018-11-17T15:57:26Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 40 XP with the following message: You made your first hyperspace jump.<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3794XP2018-11-16T20:32:23Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 20 XP with the following message: You learned how to use the transactions system. (send credits)<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown. (travel sublight)<br />
*You gained 20 XP with the following message: You found out how to assign assets. (assign something)<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3793XP2018-11-16T00:05:59Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 40 XP with the following message: You have left your homeworld for horizons unknown.<br />
*You gained 20 XP with the following message: You found out how to assign assets.<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3792XP2018-11-15T23:30:32Z<p>Ruben Wan: /* Crafting */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10 XPs when you successfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 20 XP with the following message: You found out how to assign assets.<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=XP&diff=3791XP2018-11-15T23:30:10Z<p>Ruben Wan: /* First Time XP */</p>
<hr />
<div>XP refers to your Experience Points. These are a measure of how much experience you have accumulated as your character, and generally how powerful you are. The more XP you have, the higher your level, and the more skill points you have available to allocate to your skills.<br />
<br />
==Getting XP==<br />
There are a variety of different ways of getting XP. It is received for the majority of in-game actions within the SWC interface. Some of the ways to accumulate XP are listed below:<br />
<br />
===Building===<br />
<br />
===Crafting===<br />
[[Crafting]] nets you 10XP when you sucessfully complete crafting an item.<br />
<br />
===First Time XP===<br />
*You gained 20 XP with the following message: You found out how to assign assets.<br />
*You gained 50 XP with the following message: You sent a DM to your faction.<br />
*You gained 100 XP with the following message: You used NPC Transport Service for the first time.<br />
*You gained 50 XP with the following message: You successfully found your way out of the starting building.<br />
*You gained 100 XP with the following message: You are now a faction member for the first time.<br />
*You gained 20 XP with the following message: You started using the message system.<br />
*You gained 20 XP with the following message: You sent your first faction join request<br />
<br />
===Force Training===<br />
Those who are able to use the force gain experience every time they successfully train. As well as gaining experience towards their next level of force mastery, a character also gains 15 XP for every successful training session.<br />
<br />
If training with an apprentice, should the apprentice successfully train then the apprentice gains 15 XP and the master gains 5 XP for overseeing them.<br />
<br />
===Healing===<br />
You receive XP each time you heal yourself from an injury and gain XP equal to half the amount of HP healed. The amount healed improves with your Medical Treatment skill and with the quality of medical items used. A bacta tank or medikit loaded with bacta refills heals for the greatest amount of HP, and therefore rewards you with the most XP (although a bacta tank takes a long time to complete healing and is an inefficient source of XP gain). Healing sticks provide the next highest amount of healing, followed by bacta patches.<br />
<br />
Using a healing item while on board a medical entity, which is any entity containing at least one healing room, multiplies the amount of healing done by 1.3, and therefore also provides you with more XP.<br />
<br />
===Hunting===<br />
Hunting is one of the most lucrative means of XP gain. You receive up to 40 XP per half hour combat round and cannot die. XP is decreased if you miss any shots. See the [[Hunting]] page for more information and for detailed advice about getting started and maximizing your XP gains.<br />
<br />
===Making Doors===<br />
[[Doors and Locks|Installing doors]] gives you a varying amount of XP, depending on the level of the door you are installing:<br />
<br />
{|<br />
|-<br />
| '''Level''' || '''XP'''<br />
|-<br />
| 1 || 20XP<br />
|-<br />
| 2 || 40XP<br />
|-<br />
| 3 || 80XP<br />
|}<br />
<br />
===Mining===<br />
[[Production (Mining)|Mining]] nets you a set 10XP each time a mine finishes mining. This happens after the 7 day mining period ends. If the mine is set to 'repeat' then it will continue to mine, giving you 10XP every week until it stops.<br />
<br />
===Production===<br />
<br />
===Recycling===<br />
<br />
===Travel===<br />
Ground travel enables you to gain 1 XP per surface square traveled, and crossing terrain enables you to gain 10 XP. Space travel enables you to gain 1 XP per coordinate traveled, both in sublight and in hyperspace. Traveling between ground and atmosphere in a ship, or atmosphere and orbit, enables you to gain 5 XP for that trip.<br />
<br />
===Scenarios===<br />
Participating in [[White Scenarios]] rewards you with up to 150 XP per post, based on the quality and quantity of your roleplaying post content. The average per post is around 40 XP.<br />
<br />
Participating in the Scenario Hall forum in the RPG Centre rewards you with up to 20 XP per post, also based on quality and quantity of your post content. These are easier to join than a White Scenario and require considerably less time for the moderators to complete scoring, so you receive XP more quickly.<br />
<br />
There is no limit to the number of scenarios you can participate in simultaneously on either board.<br />
<br />
[[Category:Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Construction&diff=3790Construction2018-10-07T07:42:26Z<p>Ruben Wan: /* Construction Process */</p>
<hr />
<div>Construction is a term used to categorise the creation of cities, facilities and stations and can be considered separate from [[production]]. This article attempts to cover the construction of such entities in brief.<br />
<br />
Facilities can be either built on the ground or in space, with each having a different set of requirements and restrictions. They will therefore be discussed individually.<br />
<br />
==Space Stations==<br />
[[File:Golan2.jpg|Golan II Defence Station]]<br />
<br />
Space stations are large structures built only within systems. These can serve a variety of uses, some act as defensive structures such as Golan class (see above), designed to attack enemies nearby. Others can be used for trading, production or [[recycling]].<br />
<br />
===Requirements===<br />
Before construction can commence on a station, various things must be gathered before the user can proceed.<br />
<br />
*Station Blueprints - The user must get hold of blueprints for the station they wish to build. Station blueprints are distributed primarily to factions, with different factions holding station blueprints. Government factions have the widest range of stations, holding many of the defensive and support station designs, while Smugglers and mercenary groups have facilities such as Asteroid Hideouts. The user may be able to join one of these factions in order to make use of the plans.<br />
*Raw Materials - The user will need raw materials in order to construct their station. These must be located on a [[Ships|ship]] at the site of the project. Be aware that large stations such as Golan II or Shipyard IV will require dramatically more resources to build. Also the user will need credits.<br />
*[[NPC]]s - Builder NPCs are required to construct stations. These need to be at the same system location as the planned station. A user may have anywhere between one and 25 NPCs working on a station. <br />
* [[Privileges]] - If the user is building the station for a faction then they require the relevant materials privileges to use faction resources and the relevant construction privileges.<br />
* The area of space the user wishes to build in must not contain another station, star or black hole.<br />
* Build Permissions - Users may build a station in orbit of a planet however in order to do so, the request must be approved by the sector owner. Before construction can commence, a build request must be submitted to the owning faction stating the precise nature of the project for the factions consideration. If approved then you may build only the requested facility.<br />
<br />
===Construction Process===<br />
<br />
Once the above has been considered, the user is ready to build. Proceed to the entrance room of the ship to find the option for Station Construction. The preview will show the intended location of the station and a time estimate will be provided. The user may then assign any number of builder NPCs to the project, with more builders decreasing the time taken. Additionally the users management skill will reduce the financial cost and time requirements.<br />
<br />
Once accepted the project will commence. The station foundations are placed in the system and will be noticeable effective immediatly. All raw materials and NPCs involved in the project transfer onto the station, at which point the user is free to move along and come back at a later date. Note that stations will take a long time to produce, some can take several months to build. Once completed, an amount of experience is provided to the user as well as all NPCs.<br />
<br />
===Pausing/Aborting Construction===<br />
<br />
Once a construction project has started it can be halted through the stations management section. The project will then be stopped. A project can remain halted indefinitely without problem.<br />
<br />
Alternatively the project can be cancelled remotely by anyone with sufficient privileges to do so or the original builder. When the project is cancelled there is the option to return any used resources to any ship at the same location. The amount of resources returned is equal to the percentage of the project remaining minus 10%. It will also take a few hours to take the station apart, the closer it is to completion the longer it will take to dismantle.<br />
<br />
All NPCs will finally leave the station remains once completely dismantled and can be collected in a specialist escape pod.<br />
<br />
==Ground Facilities==<br />
Ground facilities are structures based on a planets surface and are built in mostly the same way to stations also having similar requirements and limitations.<br />
<br />
===City Placement===<br />
A user cannot start construction on a planet straight away. First any space on the ground which needs construction must be developed into a city. The person must descend to the planets surface to perform what is known as "slabbing". This converts the empty surface tile into a city ready for construction.<br />
<br />
The process costs an amount of credits between one and three million credits depending upon the terrain type being used and will take an hour. It may also cost an extra half million if the planet is of a particularly dangerous atmosphere. This cost can be paid by either the individual or, if built for faction purposes, faction credits. The user does not need any NPC for this task.<br />
<br />
Alternatively the user may opt to make the city a hidden city. Hidden cities do not appear on planetary maps and are not visible from above unless a character is in the atmosphere directly above.<br />
<br />
Caution, if the city is empty for more than three months the city will be removed and the slabbing costs will not be returned.<br />
<br />
===Facility Construction Requirements===<br />
<br />
Once a city has been founded, the user is able to construct facilities. Before building though, it is adviseable to use the [http://www.swcombine.com/citydesigner/| Combine City Designer]. This will allow the user to plan out their city and identify if their design is valid, whether it will have sufficient power etc. The designer will also show the amount of materials required.<br />
<br />
Before a user can construct there are requirements, many of these the same as space stations such as the need for facility blueprints. Again various faction types have the ability to create such buildings. Otherwise the user still needs raw materials, credits, NPC builders as well as permissions from the city owner to build.<br />
<br />
Additional concerns:<br />
* Validity - A facility has slightly different requirements in that it MUST have two completely free sides to build roads along them. Note that the edges of the city do not count as free space.<br />
* Power - Once completed, a facility will require power to function. This can be provided from any Power Generators in the same city. Without power it cannot perform the majority of its functions.<br />
<br />
===Construction Process===<br />
The resources to commence construction must be available in any ship or pre-existing facility in the city. Once again faction privileges are required to use faction resources.<br />
<br />
The user must have builder NPCs in their party and must enter the city. In order to start construction, the user must stand in a square adjacent to the planned facility. <br />
<br />
The user may then name the facility, select a type of facility and the ownership of the finished object. Note that some items MUST be owned by a faction, such as religious or defensive facilities. The user may select the orientation of the finished city, either horizontally or vertically.<br />
<br />
The next step will be to see how the city will appear with the finished building, which is demonstrated on the preview. The design may also be changed by the user to suit the planets environment or design, finally the number of builders can be assigned to the project. The maximum number of builders which can be assigned is 10, with more reducing the time slightly as well as the Management skill. It is possible to start construction with a number of Builders and later add more Builders (within the maximum 10 NPCs per facility limit). NPCs are added through the Party command menu.<br />
<br />
Once the project has been started the user is free to move somewhere else and allow the NPC to work. Once completed the builder and manager will receive experience points.<br />
<br />
===Pausing/Aborting Construction===<br />
Construction work can be halted on a project by removing NPCs from the project. Most commonly this happens when an NPC is arrested. If the number of active NPCs reaches zero, production stops. NPCs can then be re added if necessary. Construction can also be halted through facility management options.<br />
<br />
Additionally it is possible to abort the production, materials may be returned to any ship, vehicle or suitable facility. As per before, resources returned equals the percentage left on the project minus 10 percent.<br />
[[Category:Advanced Activities]]<br />
[[Category:Game Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Construction&diff=3789Construction2018-10-07T07:32:02Z<p>Ruben Wan: /* Construction Process */</p>
<hr />
<div>Construction is a term used to categorise the creation of cities, facilities and stations and can be considered separate from [[production]]. This article attempts to cover the construction of such entities in brief.<br />
<br />
Facilities can be either built on the ground or in space, with each having a different set of requirements and restrictions. They will therefore be discussed individually.<br />
<br />
==Space Stations==<br />
[[File:Golan2.jpg|Golan II Defence Station]]<br />
<br />
Space stations are large structures built only within systems. These can serve a variety of uses, some act as defensive structures such as Golan class (see above), designed to attack enemies nearby. Others can be used for trading, production or [[recycling]].<br />
<br />
===Requirements===<br />
Before construction can commence on a station, various things must be gathered before the user can proceed.<br />
<br />
*Station Blueprints - The user must get hold of blueprints for the station they wish to build. Station blueprints are distributed primarily to factions, with different factions holding station blueprints. Government factions have the widest range of stations, holding many of the defensive and support station designs, while Smugglers and mercenary groups have facilities such as Asteroid Hideouts. The user may be able to join one of these factions in order to make use of the plans.<br />
*Raw Materials - The user will need raw materials in order to construct their station. These must be located on a [[Ships|ship]] at the site of the project. Be aware that large stations such as Golan II or Shipyard IV will require dramatically more resources to build. Also the user will need credits.<br />
*[[NPC]]s - Builder NPCs are required to construct stations. These need to be at the same system location as the planned station. A user may have anywhere between one and 25 NPCs working on a station. <br />
* [[Privileges]] - If the user is building the station for a faction then they require the relevant materials privileges to use faction resources and the relevant construction privileges.<br />
* The area of space the user wishes to build in must not contain another station, star or black hole.<br />
* Build Permissions - Users may build a station in orbit of a planet however in order to do so, the request must be approved by the sector owner. Before construction can commence, a build request must be submitted to the owning faction stating the precise nature of the project for the factions consideration. If approved then you may build only the requested facility.<br />
<br />
===Construction Process===<br />
<br />
Once the above has been considered, the user is ready to build. Proceed to the entrance room of the ship to find the option for Station Construction. The preview will show the intended location of the station and a time estimate will be provided. The user may then assign any number of builder NPCs to the project, with more builders decreasing the time taken. Additionally the users management skill will reduce the financial cost and time requirements.<br />
<br />
Once accepted the project will commence. The station foundations are placed in the system and will be noticeable effective immediatly. All raw materials and NPCs involved in the project transfer onto the station, at which point the user is free to move along and come back at a later date. Note that stations will take a long time to produce, some can take several months to build. Once completed, an amount of experience is provided to the user as well as all NPCs.<br />
<br />
===Pausing/Aborting Construction===<br />
<br />
Once a construction project has started it can be halted through the stations management section. The project will then be stopped. A project can remain halted indefinitely without problem.<br />
<br />
Alternatively the project can be cancelled remotely by anyone with sufficient privileges to do so or the original builder. When the project is cancelled there is the option to return any used resources to any ship at the same location. The amount of resources returned is equal to the percentage of the project remaining minus 10%. It will also take a few hours to take the station apart, the closer it is to completion the longer it will take to dismantle.<br />
<br />
All NPCs will finally leave the station remains once completely dismantled and can be collected in a specialist escape pod.<br />
<br />
==Ground Facilities==<br />
Ground facilities are structures based on a planets surface and are built in mostly the same way to stations also having similar requirements and limitations.<br />
<br />
===City Placement===<br />
A user cannot start construction on a planet straight away. First any space on the ground which needs construction must be developed into a city. The person must descend to the planets surface to perform what is known as "slabbing". This converts the empty surface tile into a city ready for construction.<br />
<br />
The process costs an amount of credits between one and three million credits depending upon the terrain type being used and will take an hour. It may also cost an extra half million if the planet is of a particularly dangerous atmosphere. This cost can be paid by either the individual or, if built for faction purposes, faction credits. The user does not need any NPC for this task.<br />
<br />
Alternatively the user may opt to make the city a hidden city. Hidden cities do not appear on planetary maps and are not visible from above unless a character is in the atmosphere directly above.<br />
<br />
Caution, if the city is empty for more than three months the city will be removed and the slabbing costs will not be returned.<br />
<br />
===Facility Construction Requirements===<br />
<br />
Once a city has been founded, the user is able to construct facilities. Before building though, it is adviseable to use the [http://www.swcombine.com/citydesigner/| Combine City Designer]. This will allow the user to plan out their city and identify if their design is valid, whether it will have sufficient power etc. The designer will also show the amount of materials required.<br />
<br />
Before a user can construct there are requirements, many of these the same as space stations such as the need for facility blueprints. Again various faction types have the ability to create such buildings. Otherwise the user still needs raw materials, credits, NPC builders as well as permissions from the city owner to build.<br />
<br />
Additional concerns:<br />
* Validity - A facility has slightly different requirements in that it MUST have two completely free sides to build roads along them. Note that the edges of the city do not count as free space.<br />
* Power - Once completed, a facility will require power to function. This can be provided from any Power Generators in the same city. Without power it cannot perform the majority of its functions.<br />
<br />
===Construction Process===<br />
The resources to commence construction must be available in any ship or pre-existing facility in the city. Once again faction privileges are required to use faction resources.<br />
<br />
The user must have builder NPCs in their party and must enter the city. In order to start construction, the user must stand in a square adjacent to the planned facility. <br />
<br />
The user may then name the facility, select a type of facility and the ownership of the finished object. Note that some items MUST be owned by a faction, such as religious or defensive facilities. The user may select the orientation of the finished city, either horizontally or vertically.<br />
<br />
The next step will be to see how the city will appear with the finished building, which is demonstrated on the preview. The design may also be changed by the user to suit the planets environment or design, finally the number of builders can be assigned to the project. The maximum number of builders which can be assigned is 10, with more reducing the time slightly as well as the Management skill. It is possible to start construction with a number of Builders and later add more Builders (within the maximum 10 NPCs per facility limit).<br />
<br />
Once the project has been started the user is free to move somewhere else and allow the NPC to work. Once completed the builder and manager will receive experience points.<br />
<br />
===Pausing/Aborting Construction===<br />
Construction work can be halted on a project by removing NPCs from the project. Most commonly this happens when an NPC is arrested. If the number of active NPCs reaches zero, production stops. NPCs can then be re added if necessary. Construction can also be halted through facility management options.<br />
<br />
Additionally it is possible to abort the production, materials may be returned to any ship, vehicle or suitable facility. As per before, resources returned equals the percentage left on the project minus 10 percent.<br />
[[Category:Advanced Activities]]<br />
[[Category:Game Features]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3775SWC LISP2018-09-15T22:10:44Z<p>Ruben Wan: /* Lists */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|floor || || || || ||<br />
|-<br />
|ceil || || || || ||<br />
|-<br />
|round || || || || ||<br />
|-<br />
|log || || || || ||<br />
|-<br />
|exp || || || || ||<br />
|-<br />
|modulo || || || || ||<br />
|-<br />
|stochastic_round || || || || ||<br />
|-<br />
|list-of-zeros ||number||Makes a list of ''number'' 0s|| || ||(load "mathematics")<br />
|-<br />
|toDigits ||number base||Convert a positive whole ''number'' to its digit representation in ''base''. If you pass a floating point ''number'', it will be rounded down || || ||(load "mathematics")<br />
|-<br />
|digits-to-base ||list baselist ||Takes a ''list'' of digits and converts them to a base representation as provided in ''baselist'' || || ||(load "mathematics")<br />
|-<br />
|fromDigits ||digits base||List of ''digits'' in base ''base'' and converts to decimal || || ||(load "mathematics")<br />
|-<br />
|add-leading-digits ||digits n-digits ||Takes a list of ''digits'' and normalises it to N-digits. Less than N-digits adds leading zeros || || ||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
| make-seq ||number (function n) ||Creates a list of integer ''number''+1 terms using the passed ''function'' of the termid. Function must take one integer as a parameter ||1. (make-seq 3 (lambda (n) (+ n 1)))<br />2. (make-seq 2 (lambda (n) 1)) ||1. '(4 3 2 1)<br />2. '(1 1 1) || (load "funlib") <br />
|-<br />
| find-matches-in ||val searchlist (matchfun?) || || || || (load "funlib")<br />
|-| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| find-pos-of-matches-in ||val searchlist (counter) (matchfun?) || || || || (load "funlib")<br />
|-<br />
| drop-first-n ||num list ||Removes first ''num'' elements of ''list'' || || || (load "funlib")<br />
|-<br />
| remove-duplicates ||list ||Removes duplicates from one-dimensional list of atmos ''list'' || || || (load "funlib")<br />
|-<br />
| set-nth ||list nth val ||Returns ''list'' with the ''nth'' element replaced with ''val'' || || || (load "funlib")<br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
| has-room-in-party || || || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(say "Hello World!") ||"Hello World!" || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(describe "The droid beeps and burps.") ||''The droid beeps and burps.'' || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(ooc "Now go to the mentioned location and talk to the NPC there.") || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.||(add-response "Wow, I didn't know that!" explainmore) ||say "Wow, I didn't know that!" || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. ||(add-action " exit the room." room12) ||''You exit the room.'' || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
==Other Resources==<br />
You can also check out:<br />
http://racket-lang.org/ which is a version of LISP similar to SWC-Lisp and decent to practice with to get the basic idea of programming in LISP.<br />
<br />
There is also [http://lisp.plasticki.com/ LISP In Small Parts] which is a good simple overview and basic introduction to LISP's methodology of programming. It primarily focuses on thinking about how to use the language, rather than memorizing the CLISP native functions (which won't help you in SWC-LISP).<br />
<br />
===Other Reading===<br />
*[http://www.swcombine.com/rules/?Scripts Scripts Rules Page]<br />
*[http://www.swcombine.com/forum/thread.php?thread=66316&page=0 LISP Changelog Thread]<br />
*[http://www.swcombine.com/forum/thread.php?thread=67116&post=774948#post774948 Public Script Modules List]<br />
*[http://dev.swcombine.com/~selatos/scripting.pdf Original LISP Introduction PDF from Selatos]<br />
*[https://docs.google.com/document/d/1yLxbBREmN59W6cu8hwbV2C39Qdi3M2t7F82AF4lBYx0/ Kay Dallben's Starter Guide]<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3774SWC LISP2018-09-15T20:27:09Z<p>Ruben Wan: /* Arithmetic Operators */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|floor || || || || ||<br />
|-<br />
|ceil || || || || ||<br />
|-<br />
|round || || || || ||<br />
|-<br />
|log || || || || ||<br />
|-<br />
|exp || || || || ||<br />
|-<br />
|modulo || || || || ||<br />
|-<br />
|stochastic_round || || || || ||<br />
|-<br />
|list-of-zeros ||number||Makes a list of ''number'' 0s|| || ||(load "mathematics")<br />
|-<br />
|toDigits ||number base||Convert a positive whole ''number'' to its digit representation in ''base''. If you pass a floating point ''number'', it will be rounded down || || ||(load "mathematics")<br />
|-<br />
|digits-to-base ||list baselist ||Takes a ''list'' of digits and converts them to a base representation as provided in ''baselist'' || || ||(load "mathematics")<br />
|-<br />
|fromDigits ||digits base||List of ''digits'' in base ''base'' and converts to decimal || || ||(load "mathematics")<br />
|-<br />
|add-leading-digits ||digits n-digits ||Takes a list of ''digits'' and normalises it to N-digits. Less than N-digits adds leading zeros || || ||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
| has-room-in-party || || || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(say "Hello World!") ||"Hello World!" || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(describe "The droid beeps and burps.") ||''The droid beeps and burps.'' || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(ooc "Now go to the mentioned location and talk to the NPC there.") || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.||(add-response "Wow, I didn't know that!" explainmore) ||say "Wow, I didn't know that!" || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. ||(add-action " exit the room." room12) ||''You exit the room.'' || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
==Other Resources==<br />
You can also check out:<br />
http://racket-lang.org/ which is a version of LISP similar to SWC-Lisp and decent to practice with to get the basic idea of programming in LISP.<br />
<br />
There is also [http://lisp.plasticki.com/ LISP In Small Parts] which is a good simple overview and basic introduction to LISP's methodology of programming. It primarily focuses on thinking about how to use the language, rather than memorizing the CLISP native functions (which won't help you in SWC-LISP).<br />
<br />
===Other Reading===<br />
*[http://www.swcombine.com/rules/?Scripts Scripts Rules Page]<br />
*[http://www.swcombine.com/forum/thread.php?thread=66316&page=0 LISP Changelog Thread]<br />
*[http://www.swcombine.com/forum/thread.php?thread=67116&post=774948#post774948 Public Script Modules List]<br />
*[http://dev.swcombine.com/~selatos/scripting.pdf Original LISP Introduction PDF from Selatos]<br />
*[https://docs.google.com/document/d/1yLxbBREmN59W6cu8hwbV2C39Qdi3M2t7F82AF4lBYx0/ Kay Dallben's Starter Guide]<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3773SWC LISP2018-09-15T19:40:44Z<p>Ruben Wan: /* Others */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|floor || || || || ||<br />
|-<br />
|ceil || || || || ||<br />
|-<br />
|round || || || || ||<br />
|-<br />
|log || || || || ||<br />
|-<br />
|exp || || || || ||<br />
|-<br />
|modulo || || || || ||<br />
|-<br />
|stochastic_round || || || || ||<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
| has-room-in-party || || || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(say "Hello World!") ||"Hello World!" || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(describe "The droid beeps and burps.") ||''The droid beeps and burps.'' || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(ooc "Now go to the mentioned location and talk to the NPC there.") || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.||(add-response "Wow, I didn't know that!" explainmore) ||say "Wow, I didn't know that!" || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. ||(add-action " exit the room." room12) ||''You exit the room.'' || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
==Other Resources==<br />
You can also check out:<br />
http://racket-lang.org/ which is a version of LISP similar to SWC-Lisp and decent to practice with to get the basic idea of programming in LISP.<br />
<br />
There is also [http://lisp.plasticki.com/ LISP In Small Parts] which is a good simple overview and basic introduction to LISP's methodology of programming. It primarily focuses on thinking about how to use the language, rather than memorizing the CLISP native functions (which won't help you in SWC-LISP).<br />
<br />
===Other Reading===<br />
*[http://www.swcombine.com/rules/?Scripts Scripts Rules Page]<br />
*[http://www.swcombine.com/forum/thread.php?thread=66316&page=0 LISP Changelog Thread]<br />
*[http://www.swcombine.com/forum/thread.php?thread=67116&post=774948#post774948 Public Script Modules List]<br />
*[http://dev.swcombine.com/~selatos/scripting.pdf Original LISP Introduction PDF from Selatos]<br />
*[https://docs.google.com/document/d/1yLxbBREmN59W6cu8hwbV2C39Qdi3M2t7F82AF4lBYx0/ Kay Dallben's Starter Guide]<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Talk:SWC_LISP&diff=3772Talk:SWC LISP2018-09-15T18:51:21Z<p>Ruben Wan: </p>
<hr />
<div>same-time? and cmp-time do the same thing and are in the same library.<br />
<br />
rand-from-list Y16D1 and rand-from-list-unique are two different functions or the same?<br />
<br />
sublist-firstof or sublists-firstof?<br />
<br />
on Y18D5 get-entity alone is not present, there are several get-entity-somethingMore. Is it ok or is it missing?</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Talk:SWC_LISP&diff=3771Talk:SWC LISP2018-09-15T18:47:50Z<p>Ruben Wan: </p>
<hr />
<div>same-time? and cmp-time do the same thing and are in the same library.<br />
<br />
rand-from-list Y16D1 and rand-from-list-unique are two different functions or the same?<br />
<br />
sublist-firstof or sublists-firstof?</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3770SWC LISP2018-09-15T18:42:24Z<p>Ruben Wan: /* Arithmetic Operators */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|floor || || || || ||<br />
|-<br />
|ceil || || || || ||<br />
|-<br />
|round || || || || ||<br />
|-<br />
|log || || || || ||<br />
|-<br />
|exp || || || || ||<br />
|-<br />
|modulo || || || || ||<br />
|-<br />
|stochastic_round || || || || ||<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(say "Hello World!") ||"Hello World!" || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(describe "The droid beeps and burps.") ||''The droid beeps and burps.'' || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(ooc "Now go to the mentioned location and talk to the NPC there.") || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.||(add-response "Wow, I didn't know that!" explainmore) ||say "Wow, I didn't know that!" || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. ||(add-action " exit the room." room12) ||''You exit the room.'' || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
==Other Resources==<br />
You can also check out:<br />
http://racket-lang.org/ which is a version of LISP similar to SWC-Lisp and decent to practice with to get the basic idea of programming in LISP.<br />
<br />
There is also [http://lisp.plasticki.com/ LISP In Small Parts] which is a good simple overview and basic introduction to LISP's methodology of programming. It primarily focuses on thinking about how to use the language, rather than memorizing the CLISP native functions (which won't help you in SWC-LISP).<br />
<br />
===Other Reading===<br />
*[http://www.swcombine.com/rules/?Scripts Scripts Rules Page]<br />
*[http://www.swcombine.com/forum/thread.php?thread=66316&page=0 LISP Changelog Thread]<br />
*[http://www.swcombine.com/forum/thread.php?thread=67116&post=774948#post774948 Public Script Modules List]<br />
*[http://dev.swcombine.com/~selatos/scripting.pdf Original LISP Introduction PDF from Selatos]<br />
*[https://docs.google.com/document/d/1yLxbBREmN59W6cu8hwbV2C39Qdi3M2t7F82AF4lBYx0/ Kay Dallben's Starter Guide]<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3769SWC LISP2018-09-15T18:41:17Z<p>Ruben Wan: /* Arithmetic Operators */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|floor || || || || ||<br />
|-<br />
|ceil || || || || ||<br />
|-<br />
|round || || || || ||<br />
|-<br />
|log || || || || ||<br />
|-<br />
|-exp || || || || ||<br />
|-<br />
|modulo || || || || ||<br />
|-<br />
|stochastic_round || || || || ||<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(say "Hello World!") ||"Hello World!" || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(describe "The droid beeps and burps.") ||''The droid beeps and burps.'' || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(ooc "Now go to the mentioned location and talk to the NPC there.") || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.||(add-response "Wow, I didn't know that!" explainmore) ||say "Wow, I didn't know that!" || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. ||(add-action " exit the room." room12) ||''You exit the room.'' || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
==Other Resources==<br />
You can also check out:<br />
http://racket-lang.org/ which is a version of LISP similar to SWC-Lisp and decent to practice with to get the basic idea of programming in LISP.<br />
<br />
There is also [http://lisp.plasticki.com/ LISP In Small Parts] which is a good simple overview and basic introduction to LISP's methodology of programming. It primarily focuses on thinking about how to use the language, rather than memorizing the CLISP native functions (which won't help you in SWC-LISP).<br />
<br />
===Other Reading===<br />
*[http://www.swcombine.com/rules/?Scripts Scripts Rules Page]<br />
*[http://www.swcombine.com/forum/thread.php?thread=66316&page=0 LISP Changelog Thread]<br />
*[http://www.swcombine.com/forum/thread.php?thread=67116&post=774948#post774948 Public Script Modules List]<br />
*[http://dev.swcombine.com/~selatos/scripting.pdf Original LISP Introduction PDF from Selatos]<br />
*[https://docs.google.com/document/d/1yLxbBREmN59W6cu8hwbV2C39Qdi3M2t7F82AF4lBYx0/ Kay Dallben's Starter Guide]<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3768SWC LISP2018-09-15T18:39:11Z<p>Ruben Wan: /* Conversational Functions */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(say "Hello World!") ||"Hello World!" || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(describe "The droid beeps and burps.") ||''The droid beeps and burps.'' || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.||(ooc "Now go to the mentioned location and talk to the NPC there.") || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.||(add-response "Wow, I didn't know that!" explainmore) ||say "Wow, I didn't know that!" || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. ||(add-action " exit the room." room12) ||''You exit the room.'' || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
==Other Resources==<br />
You can also check out:<br />
http://racket-lang.org/ which is a version of LISP similar to SWC-Lisp and decent to practice with to get the basic idea of programming in LISP.<br />
<br />
There is also [http://lisp.plasticki.com/ LISP In Small Parts] which is a good simple overview and basic introduction to LISP's methodology of programming. It primarily focuses on thinking about how to use the language, rather than memorizing the CLISP native functions (which won't help you in SWC-LISP).<br />
<br />
===Other Reading===<br />
*[http://www.swcombine.com/rules/?Scripts Scripts Rules Page]<br />
*[http://www.swcombine.com/forum/thread.php?thread=66316&page=0 LISP Changelog Thread]<br />
*[http://www.swcombine.com/forum/thread.php?thread=67116&post=774948#post774948 Public Script Modules List]<br />
*[http://dev.swcombine.com/~selatos/scripting.pdf Original LISP Introduction PDF from Selatos]<br />
*[https://docs.google.com/document/d/1yLxbBREmN59W6cu8hwbV2C39Qdi3M2t7F82AF4lBYx0/ Kay Dallben's Starter Guide]<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3767SWC LISP2018-09-15T08:19:11Z<p>Ruben Wan: /* Conversational Functions */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.|| || || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
==Other Resources==<br />
You can also check out:<br />
http://racket-lang.org/ which is a version of LISP similar to SWC-Lisp and decent to practice with to get the basic idea of programming in LISP.<br />
<br />
There is also [http://lisp.plasticki.com/ LISP In Small Parts] which is a good simple overview and basic introduction to LISP's methodology of programming. It primarily focuses on thinking about how to use the language, rather than memorizing the CLISP native functions (which won't help you in SWC-LISP).<br />
<br />
===Other Reading===<br />
*[http://www.swcombine.com/rules/?Scripts Scripts Rules Page]<br />
*[http://www.swcombine.com/forum/thread.php?thread=66316&page=0 LISP Changelog Thread]<br />
*[http://www.swcombine.com/forum/thread.php?thread=67116&post=774948#post774948 Public Script Modules List]<br />
*[http://dev.swcombine.com/~selatos/scripting.pdf Original LISP Introduction PDF from Selatos]<br />
*[https://docs.google.com/document/d/1yLxbBREmN59W6cu8hwbV2C39Qdi3M2t7F82AF4lBYx0/ Kay Dallben's Starter Guide]<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Scripting&diff=3766Scripting2018-09-15T08:15:35Z<p>Ruben Wan: /* Other Resources */</p>
<hr />
<div>The scripting language used by SWC is currently available for speeches of Custom NPCs and for interactions with items (e.g. egg incubator). <br />
<br />
The new language ([[SWC LISP]]) is a big step ahead from the old system. Here we want to list the major differences with the old system to ease the conversion from the old system to the new one.<br />
<br />
==Wildcards (OLD SWC Script Syntax)==<br />
{|class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! SWC Lisp<br />
! Old Wildcard<br />
! Description<br />
! Example<br />
! Default<br />
! For Custom NPCs?<br />
|-<br />
|(get-name self) || %npc.name% || NPC's name || Joe Bloggs || N/A || Yes<br />
|-<br />
|(get-race self) || %npc.race% ||NPC's race ||Nautolan ||N/A ||Yes<br />
|-<br />
| (get-infofield self) ||%npc.infofield% ||NPC's infofield ||Master Carpenter ||N/A ||Yes<br />
|-<br />
|(get-gender self) ||%npc.gender% ||NPC's gender ||Male ||N/A ||Yes<br />
|-<br />
|(get-formal self) ||%npc.formal% ||NPC's formal greeting ||Sir/Ma'am ||N/A ||Yes<br />
|-<br />
|(is-ally? self) ||%npc.ally% ||is NPC IFF friendly? ||N/A ||N/A ||Yes<br />
|-<br />
|(is-enemy? self) ||%npc.enemy% ||is NPC IFF enemy? ||N/A ||N/A ||Yes<br />
|-<br />
|(is-neutral? self) ||%npc.neutral% ||is NPC IFF neutral? ||N/A ||N/A ||Yes<br />
|-<br />
|(is-unharmed? self) ||%npc.unharmed% ||is NPC unharmed? - requires (load "swclib") ||N/A ||N/A ||Yes<br />
|-<br />
|(is-slightly-wounded? self) ||%npc.slightlywounded% ||is NPC slightly wounded?- requires (load "swclib") ||N/A ||N/A ||Yes<br />
|-<br />
|(is-wounded? self) ||%npc.wounded% ||is NPC wounded?- requires (load "swclib")||N/A ||N/A ||Yes<br />
|-<br />
|(is-badly-wounded? self) ||%npc.badlywounded% ||is NPC badly wounded?- requires (load "swclib") ||N/A ||N/A ||Yes<br />
|-<br />
|(get-name character) ||%character.name% ||Character's handle ||Selatos ||N/A ||Yes<br />
|-<br />
|(get-race character) ||%character.race% ||Character's race ||Human ||N/A ||Yes<br />
|-<br />
| (get-infofield character) ||%character.infofield% ||Character's 1st infofield ||Emperor ||Empty String ||Yes<br />
|-<br />
| (get-infofield2 character) ||%character.infofield2% ||Character's 2nd infofield ||1st Recon Division ||Empty String ||Yes<br />
|-<br />
| (get-infofield3 character) ||%character.infofield3% ||Character's 3rd infofield ||2nd Expansionary Fleet ||Empty String ||Yes<br />
|-<br />
|(get-gender character) ||%character.gender% ||Character's gender ||Male ||N/A ||Yes<br />
|-<br />
|(is-unharmed? character) ||%character.unharmed% ||is Character unharmed? - requires (load "swclib")||N/A ||N/A ||Yes<br />
|-<br />
|(is-slightly-wounded? character) ||%character.slightlywounded% ||is Character slightly wounded? - requires (load "swclib")||N/A ||N/A ||]Yes<br />
|-<br />
|(is-wounded? character) ||%character.wounded% ||is Character wounded? - requires (load "swclib")||N/A ||N/A ||Yes<br />
|-<br />
|(is-badly-wounded? character) || %character.badlywounded% ||is Character badly wounded?- requires (load "swclib") ||N/A ||N/A ||Yes<br />
|-<br />
|(get-formal character) || %character.formal% ||Character's formal greeting ||Sir/Ma'am ||N/A ||Yes<br />
|-<br />
|(get-entity-faction character) || %character.faction% ||Character's current faction ||New Republic ||Freelance ||Yes<br />
|-<br />
|(is-owner? character) || %character.isowner% ||Is character the owner of the NPC ||Produces no output ||Empty String ||Yes<br />
|-<br />
|(is-manager? character) || %character.ismanager% ||Is character the manager of the NPC ||Produces no output ||Empty String ||Yes<br />
|-<br />
|(is-pilot? character) || %character.issupervisor% ||Is character the owner of the NPC ||Produces no output ||Empty String ||Yes<br />
|-<br />
|(get-name (get-entity-faction character)) || %faction.name% ||Character's faction's name ||New Republic ||Empty string (if freelance) ||Yes<br />
|-<br />
|(is-freelancer? character) || n.a. ||is the character a freelancer? || || ||Yes<br />
|-<br />
|(faction-type (get-entity-faction character)) || %faction.type% ||Character's faction's type ||Mining ||Empty string (if freelance) ||Yes<br />
|-<br />
|(faction-leader (get-entity-faction character)) || %faction.leader% ||Character's faction's leaders name ||Ellias ||Empty String (if freelance) ||Yes<br />
|-<br />
|(faction-website (get-entity-faction character)) || %faction.website% ||Character's faction's leaders name ||http://swcombine.com (Link) ||Empty string (if freelance) ||Yes<br />
|-<br />
| || %owner.name% ||Name of the NPC's owner ||Darkness ||Empty string if special owner (Market, None) ||Yes<br />
|-<br />
| || %owner.entityType% ||Type of the NPC's owner ||Faction or Character ||Empty string if special owner (Market, None) ||Yes<br />
|-<br />
| || %owner.infofield% ||Owner's 1st infofield ||Emperor ||Empty String ||Yes<br />
|-<br />
| || %owner.infofield2% ||Owner's 2nd infofield ||1st Recon Division ||Empty String ||Yes<br />
|-<br />
| || %owner.infofield3% ||Owner's 3rd infofield ||2nd Expansionary Fleet ||Empty String ||Yes<br />
|-<br />
|(city-name character) || %location.city% ||Current city name ||City 327 ||Unknown ||Yes*<br />
|-<br />
|(planet-name character) || %location.planet% ||Current planet name ||Glee Anselm ||Unknown ||Yes*<br />
|-<br />
|(system-name character) || %location.system% ||Current system name ||Danju ||Unknown ||Yes*<br />
|-<br />
|(sector-name character) || %location.sector% ||Current sector name ||Tapani ||Unknown ||Yes*<br />
|-<br />
| (get-destination entity) || %location.destination% ||Destination name ||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city) ||Unknown ||Yes*<br />
|-<br />
|(get-eta entity) || %location.eta% ||ETA for current travel ||3 days, 24 hours and 5 minutes ||Unknown ||Yes*<br />
|-<br />
|(is-traveling? character) || n.a. ||Checks if the character is traveling or not || || ||Yes<br />
|-<br />
| (get-name (get-container self))|| %container.name% ||Current container name, e.g. the ship or vehicle standing in ||Tydirium ||Unknown ||Yes<br />
|-<br />
|(get-entity-type-name (get-container self)) || %container.type% ||Current container type, e.g. the ship or vehicle standing in ||Lambda Shuttle ||Unknown ||Yes<br />
|-<br />
|(get-type entity-object) || %container.entityType% ||Current container entity type, e.g. the ship, vehicle, city, planet, station ||Ship, Vehicle, City, Planet, Space Station ||N/A ||Yes<br />
|-<br />
|(in-room? entity-object) || n.a. ||Checks if the entity is in any room at all, as opposed to outside on the surface || || ||Yes<br />
|-<br />
| cgt-year|| %cgt.year% ||Gets current CGT year ||12 ||N/A ||Yes<br />
|-<br />
| cgt-day|| %cgt.day% ||Gets current CGT day ||183 ||N/A ||Yes<br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||23 ||N/A ||Yes<br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||59 ||N/A ||Yes<br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||59 ||N/A ||Yes<br />
|-<br />
| timeofday|| %time.ofday% ||Gets current phase of day ||Morning, Afternoon, Evening ||N/A ||Yes<br />
|}<br />
Entries with a "Yes" are available for custom NPCs. Entries with a "Yes*" may have some limitations on their use (e.g. they may not be available when the NPC cannot reliably determine the information without godmodding - for example location whilst in hyperspace).<br />
<br />
==Custom NPC Environment==<br />
This is the latest posting of functions and constants available to Custom NPCs. Some of these may not be synced to Main yet. Some are also listed above in Wildcards. Where possible, the syntax, required&optional parameters and example usage & evaluation are included.<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! SWC Lisp <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Evaluation<br />
! Default eval<br />
! Testing Status<br />
|-<br />
| self || || The object running the script (NPC, item...). || Test Tickle || n/a || <br />
|- <br />
| character || || The character interacting with the object running the script. || Kay Dallben || n/a || <br />
|- <br />
| evar ||| 'name defaultValue || This is a persistent variable in the context of self. See Persistent Variables for usage notes. || special case || defaultValue || <br />
|- <br />
| ovar || 'name defaultValue || This is a persistent variable in the context of self & character. See Persistent Variables for usage notes. || special case || defaultValue || <br />
|- <br />
| svar || 'name defaultValue || This is a persistent variable in the context of the current *session*. Session is the interaction between a PC and a scripted entity. See Persistent Variables for usage notes. || special case || defaultValue || <br />
|- <br />
| #t || || This is "True" || #t || #t || <br />
|- <br />
| + || a b &d &e … || Basic addition function. Takes at least 2 numbers. || a+b || n/a || <br />
|- <br />
| - || a b &d &e … || Basic subtraction function. Takes at least 2 numbers. Evaluates as a - b - c - d … or a - (sum b…n) || a-b-c-d… || n/a || <br />
|- <br />
| > || a b || Preposition. Answers: Is a Greater than b? || #t || n/a || <br />
|- <br />
| * || a b || Basic multiplication function. Takes at least 2 parameters. || a*b || n/a || <br />
|- <br />
| / || a b || Basic division function. Takes at least 2 parameters. || a/b || n/a || <br />
|- <br />
| ge? || a b || Preposition. Answers: Is a Greater than OR equal to b? || #t || n/a || <br />
|- <br />
| >= || a b || Preposition. Answers: Is a Greater than OR equal to b? || #t || n/a || <br />
|- <br />
| le? || a b || Preposition. Answers: Is a less than OR equal to b? || #t || n/a || <br />
|- <br />
| <= || a b || Preposition. Answers: Is a less than OR equal to b? || #t || n/a || <br />
|- <br />
| gt? || a b || Preposition. Answers: Is a Greater than b? || #t || n/a || <br />
|- <br />
| || || || || || <br />
|- <br />
| lt? || a b || Preposition. Answers: Is a less than b? || #t || n/a || <br />
|- <br />
| < || a b || Preposition. Answers: Is a less than b? || #t || n/a || <br />
|- <br />
| and || a b &c… || Logical Operand. #t if all its parameters are #t || #t || n/a || <br />
|- <br />
| or || a b &c… || Logical Operand. #t if any of its parameters are #t. If it finds a #t, it will stop evaluating the rest of the parameters. || #t || n/a || <br />
|- <br />
| not || a || Logical Operand. #t if a is #f || #t || n/a || <br />
|- <br />
| concat || stringA &stringB || a concatenated string made up of the provided strings. || abc… || n/a || <br />
|- <br />
| strlen || string || number of characters in the provided string a || 4 || n/a || <br />
|- <br />
| trim || string &character_mask || removes:"\0" null "\t" tab "\n" new line "\x0B" vertical tabs "\r" carriage returns and " " spaces. &character_mask can be used to trim only some of those. || sample string || n/a || <br />
|- <br />
| substr || string start &length || a string made of of the sequential characters within the provided string, beginning at the start character, and ending at &length, if provided. If &length is not provided, the rest of the string is provided. || ample string || n/a || <br />
|- <br />
| stripos || stringA searchFor &offset || the start position of searchFor if contained in stringA, beginning the search at &offset. || (stripos "sample string" "mp") -> 2 || n/a || <br />
|- <br />
| length || listA || number of elements in listA || (length (list 'a 'b 'c 'd 4)) -> 5 || n/a || <br />
|- <br />
| reverse || listA || a list of the reversed elements of listA || (reverse (list 'a 'b 'c)) -> (c b a) || n/a || <br />
|- <br />
| sublist || listA offset &length &preserve_keys || a list of the elements of listA beginning at offset and continuing to the end of listA OR to &length elements if provided. &preserve_keys should be #t or nil. NOTE: sublist will (perhaps unexpectedly) return strings from a list of symbols. Be aware when using it to get a sublist involving symbols. This is important because (eq? 'a "a") -> #f|| (sublist (list "a" 'b "c") 0 2) -> `("a" "b") || n/a || <br />
|- <br />
| sort || listA || a list of sorted elements of listA. Sort is alphanumeric. || (sort `(b c a)) -> (a b c) || n/a || <br />
|- <br />
| nth-of || listA n || the element of listA at position n. 0 is the first element NOTE: nth-of will (perhaps unexpectedly) return strings from a list of symbols. Be aware when using it to get nth-of from a list involving symbols. This is important because (eq? 'a "a") -> #f || (nth-of `(a b c) 1) -> "b" || n/a || <br />
|- <br />
| rand || &min &max || random number between &min &max. If not provided &min is 0 and &max is ?. See Randomization topic. || (rand 0 5) -> 2 || n/a || <br />
|- <br />
| rand-from-list || listA || random element from listA NOTE: Be aware that rand-from-list will not return any Symbol if you give it a list of symbols. It will return a STRING if the random element it finds is a symbol. This is important because (eq? 'a "a") -> #f|| (rand-from-list `(a b c)) -> "b" or "a" or "c" || n/a || <br />
|- <br />
| get-entity-type-id || name || Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station} || (get-entity-type-id 'Planet) -> || n/a || <br />
|- <br />
| get-type-type || typeID entityType || returns a full TYPE || (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
| get-creature-type || typeID || returns the type of Creature || (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
| get-droid-type || typeID || returns the type of Droid || (get-droid-type 14) gets the droid type obj for Pit Droids || || <br />
|- <br />
| get-item-type || typeID || returns the type of Item || (get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
| get-npc-type || typeID ||returns the type of NPC || (get-npc-type NUM) returns the type for a NPC of typeid NUM || || needs testing<br />
|- <br />
| get-type-of || entity || returns the type object for the entity ||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc) || ||<br />
|- <br />
| get-npc-owner || || returns the "NPC Owner" object || || || useful for an is-unclaimed? check.<br />
|- <br />
| get-hostile-owner || ||returns the "Hostile Owner" object || || || ie checks if it is a spawned Bandit/Creature<br />
|- <br />
| style="white-space: nowrap;"|get-market-owner || || returns the "Market Owner" object || || || <br />
|- <br />
| get-character || name || entity-object for character "name" || (get-character "Kay Dallben") || n/a || <br />
|- <br />
| get-faction || name || faction-object for faction "name" || (get-faction "Darkness") || n/a || <br />
|- <br />
| get-npc || id || npc-object for NPC with ID id || (get-npc 155408) || n/a || <br />
|- <br />
| get-quest || id || quest-object for quest with ID id || (get-quest 4408) || n/a || <br />
|- <br />
| get-item || id || item-object for item with ID id || (get-item 481099) || n/a || <br />
|- <br />
| get-ship || id || ship-object for ship with ID id || (get-ship 448088) || n/a || <br />
|- <br />
| get-vehicle || id || vehicle-object for vehicle with ID id || (get-vehicle 46846816) || n/a || <br />
|- <br />
| get-room || id || room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers. || (get-room 4478) || n/a || <br />
|- <br />
| get-id || entity || ID for the entity || (get-id (get-npc 100)) -> 100 || n/a || <br />
|- <br />
| get-name || entity || name of the object || (get-name (get-vehicle 1150488)) || n/a || <br />
|- <br />
| get-formal || entity || Sir if gender is male, Maam if gender is female. || (get-formal (get-character "Kay Dallben")) -> Sir || n/a || <br />
|- <br />
| get-infofield || entity || string of the first infofield of entity || (get-infofield (get-npc 111548)) || empty string || <br />
|- <br />
| get-infofield2 || pc-entity || string of the 2nd infofield of entity || (get-infofield2 (get-character "Kay Dallben")) || || <br />
|- <br />
| get-infofield3 || pc-entity || string of the 3rd infofield of entity || (get-infofield3 (get-character "Kay Dallben")) || || <br />
|- <br />
| get-race || entity || string representing race of the entity || (get-race self) || n/a || <br />
|- <br />
| get-gender || entity || string of the gender of entity || (get-gender self) ->Male || n/a || <br />
|- <br />
| get-hp-status-text || entity || string of the hp-status-text {unharmed, slightly-wounded, etc.} || (get-hp-status-text self) || n/a || <br />
|- <br />
| is-ally? || test &source || Preposition. Answers: is test an ally to &source (default: self) || (is-ally? (get-npc 445158)) || n/a || <br />
|- <br />
| is-neutral? || test &source || Preposition. Answers: is test neutral to &source (default: self) || (is-neutral? (get-npc 4408)) || n/a || <br />
|- <br />
| is-enemy? || test &source || Preposition. Answers is test an enemy to &source (default: self) || (is-enemy? (get-npc 4408)) || n/a || <br />
|- <br />
| is-freelancer? || test-character || Preposition. Answers: is test-character a freelancer? || (is-freelancer? (get-character "Kay Dallben")) -> #T || n/a || <br />
|- <br />
| faction-owned? || entity || Preposition. Answers: is the entity owned by a faction? || (faction-owned? self) || n/a || <br />
|- <br />
| get-entity-faction || entity || faction-object for the faction entity belongs to? || || n/a || needs testing<br />
|- <br />
| faction-type || faction-entity || type of faction || String? || || needs testing<br />
|- <br />
| faction-leader || faction-entity || leader of faction || String? || || needs testing<br />
|- <br />
| faction-website || faction-entity || website of faction || String? || || needs testing<br />
|- <br />
| get-owner || entity || owner object of entity || (get-owner self)-> Kay Dallben || || <br />
|- <br />
| get-type || entity || type of entity || type ID or string? || || needs testing<br />
|- <br />
| get-entity-type-name || entity || name of type of entity || string? || || needs testing<br />
|- <br />
| is-owner? || || Preposition. Answers: is character the owner of self || (is-owner?) -> #t || n/a || <br />
|- <br />
| is-commander? || || Preposition. Answers: is character the commander of self || (is-commander?) || || <br />
|- <br />
| is-manager? || || Preposition. Answers: is character the manager of self || (is-manager?) || || <br />
|- <br />
| is-pilot? || || Preposition. Answers: is character the pilot of self || (is-pilot?) || || <br />
|- <br />
| is-supervisor? || || Preposition. Answers: is character the supervisor of self || (is-supervisor?) || || <br />
|- <br />
| in-room? || entity || Preposition. Answers: is entity in the same room as self? || (in-room? (get-NPC 4808)) || n/a || <br />
|- <br />
| is-traveling? || entity || Preposition. Answers: is entity travelling? || (is-traveling? (get-ship 3334)) || n/a || <br />
|- <br />
| get-container || entity || entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
| get-destination || entity || destination of entity || || || needs testing<br />
|- <br />
| get-eta || entity || eta of arrival of entity to its destination || || || needs testing<br />
|- <br />
| get-location || entity || String of location (currently including hyperlinks) if viewable without godmoding. || || || needs testing<br />
|- <br />
| city-name || entity || Name of the city containing entity? || || || needs testing<br />
|- <br />
| planet-name || entity || name of the planet containing entity? || || || needs testing<br />
|- <br />
| system-name || entity || name of the system containing entity? || || || needs testing<br />
|- <br />
| sector-name || entity || name of the sector containing entity? || || || needs testing<br />
|- <br />
| send-message || sender receiver message &subject || Output: Sends a DM to receiver, from sender with message and subject &subject. Receiver and Sender must be any PC-object and self || || || needs testing<br />
|- <br />
| flash ||style="white-space: nowrap;"| type{'green 'red 'blue 'good 'bad 'info} message || Puts a small coloured bar with the message on the screen of character. || (flash 'green "You did it!") || n/a || <br />
|- <br />
| null || || null || || null || <br />
|- <br />
| empty || || Use for the empty list `() || || null || <br />
|- <br />
| nil || || aka #f || || null || <br />
|- <br />
| cgt-year || || current year || || || <br />
|- <br />
| cgt-day || || current day || || || <br />
|- <br />
| cgt-hour || || current hour || || || <br />
|- <br />
| cgt-minute || || current minute || || || <br />
|- <br />
| timeofday || || string of timeofday Morning Afternoon Evening Night || || n/a || <br />
|- <br />
| teleport-to-room || entities container room || ? || || || needs testing<br />
|- <br />
| leave-room || character direction || ? || || || needs testing<br />
|- <br />
| say || message &close || Output: NPC "says" message. &close is boolean. If true, this will start a new paragraph. || || || <br />
|- <br />
| describe || message &close || Output: NPC "describes" message. &close is boolean. If true, this will start a new paragraph. || || || <br />
|- <br />
| ooc || message &close || Output: NPC "oocs" message. &close is boolean. If true, this will start a new paragraph. || || || <br />
|- <br />
| say-c || message || Output: NPC "says" message, continuing previous paragraph and using that formatting || || || <br />
|- <br />
| describe-c || message || Output: NPC "describes" message, continuing previous paragraph and using that formatting || || || <br />
|- <br />
| ooc-c || message || Output: NPC "oocs" message, continuing previous paragraph and using that formatting || || || <br />
|- <br />
| add-response || message callback || Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
| add-action || message callback || Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
| add-text || message callback || Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
| add-input || not implemented || Input: creates a text box for the user to type something in. In progress. || || || <br />
|- <br />
|}<br />
<br />
==Conditional Statements==<br />
The biggest differences are:<br />
* the "=" is no longer used to do comparisons;<br />
<br />
Old system:<br />
<pre>!if character.race=Gungan! Don't slip over!<br />
!if character.race=Human! Humans are the best!<br />
!ifnot character.race=Human! Alien scum!</pre><br />
<br />
New system:<br />
<pre>(cond <br />
[(eq? (get-race character) "Gungan") (say "Don't slip over!") (say "Alien scum!")]<br />
[(eq? (get-race character) "Human") (say "Humans are the best!")]<br />
[#t (say "Alien scum!")])</pre><br />
OR<br />
<pre>(cond[(eq? (get-race character) "Gungan") (say "Don't slip over!") (say "Alien scum!")])<br />
(cond [(is-owner?) (say "Oh, uh. Welcome Boss!")]</pre><br />
<br />
* with ''cond'' statement, the conditions are tested sequentially until one of them is true, and then it evaluates it and stops testing. This is much like an If...ElseIf...ElseIf. This means that if you have two statements, you must put them inside the same condition. If you have multiple alternate conditions (ElseIfs) to test, you must ensure that at least one of them evaluates true '''every time'''. Commonly this is done with a final [#t] condition. <br />
* You can use ''cond'' statements as a simple IF by only including one test.<br />
<br />
Old system:<br />
<pre>Responses:<br />
!if character.race=Baragwin! !if character.gender=Female! Excuse me, how do you know I am a female? -> Baragwin female<br />
!if character.race=Baragwin! !if character.gender=Male! Excuse me, how do you know I am a male? -> Baragwin male<br />
!ifnot character.race=Baragwin! I'd like to have more information on the museum. -> info<br />
!ifnot character.race=Baragwin! What can I do here? -> what to do<br />
!ifnot character.race=Baragwin! Do I need to pay an entrance fee? -> fee</pre><br />
<br />
New system: NOTE: Technically, the last ElseIf can just be #t rather than (not (eq? (get-race character) "Baragwin")). This is because the first two checks cover all cases where the character could be a Baragwin (female or male).<br />
<pre> (cond <br />
[(and (eq? (get-race character) "Baragwin") (eq? (get-gender character) "Female")) <br />
(add-response "Excuse me, how do you know I am a female?" Baragwin-female)]<br />
[(and (eq? (get-race character) "Baragwin") (eq? (get-gender character) "Male")) <br />
(add-response "Excuse me, how do you know I am a male?" Baragwin-male)]<br />
[(not (eq? (get-race character) "Baragwin"))<br />
(add-response "I'd like to have more information on the museum." info) <br />
(add-response "What can I do here?" what-to-do)<br />
(add-response "Do I need to pay an entrance fee?" fee)][#t])</pre><br />
<br />
Note 2: Also, since the two add-responses in the first cases are so similar, you can combine them and toss the M/F determination, if important, into the Baragwin defun next conversation step.<br />
<pre>(cond <br />
[(eq? (get-race character) "Baragwin") (add-response (concat "Excuse me, how do you know I am a " (get-gender character) "?") Baragwin-female)]<br />
[#t<br />
(add-response "I'd like to have more information on the museum." info) <br />
(add-response "What can I do here?" what-to-do)<br />
(add-response "Do I need to pay an entrance fee?" fee)])<br />
</pre><br />
<br />
==Variable Examples==<br />
The following little script shows how to use session variables.<br />
(defvar hp-session-var (svar 'hp 10))<br />
(defvar str-session-var (svar 'str 5))<br />
(defvar rand-val (svar 'rand (rand 1 5)))<br />
(defvar setted-rand-val (svar 'setted-rand-val (rand 11 15)))<br />
<br />
(defun (incr-hp val)<br />
(set-var! hp-session-var (+ hp-session-var val)))<br />
<br />
(defun (incr-str val)<br />
(set-var! str-session-var (+ str-session-var val)))<br />
<br />
(defun start<br />
(ooc (concat "Your HP is: " hp-session-var ". Your Str is: " str-session-var ". The rand-val is: " rand-val ". The 'setted-rand-val' is: " setted-rand-val "." ) )<br />
(add-action "Set the setted-rand-val to store the rand between 6 and 10 for the whole session." set-rand-val)<br />
(add-action "Add 2 HP" add-2hp)<br />
(add-action "Sub 4 HP" sub-4hp)<br />
(add-action "Add Str to HP" add-str-to-hp)<br />
(add-action "Add Rand 1 - 9 to Str" add-rand-to-str))<br />
<br />
(defun add-2hp (incr-hp 2) (start))<br />
<br />
(defun sub-4hp (incr-hp -4) (start))<br />
<br />
(defun add-str-to-hp (incr-hp str-session-var) (start))<br />
<br />
(defun set-rand-val<br />
(set-var! setted-rand-val (rand 6 10)) (start))<br />
<br />
(defun add-rand-to-str (incr-str (rand 1 9)) (start))<br />
<br />
==Basic Custom NPC Interaction==<br />
===Conversation===<br />
{|<br />
! Syntax<br />
! Example of Use<br />
! Actual Output<br />
|-<br />
|'''say''' string || (say "Hello World!") || "Hello World!"<br />
|-<br />
|'''describe''' string || (describe "The droid beeps and burps.") || ''The droid beeps and burps.''<br />
|-<br />
|ooc string || (ooc "Now go to the mentioned location and talk to the NPC there.") ||<br />
|-<br />
|add-response string next-function) || (add-response "Wow, I didn't know that!" explainmore) || say "Wow, I didn't know that!"<br />
|-<br />
|add-action string next-function || (add-action " exit the room." room12) || ''You exit the room.''<br />
|}<br />
<br />
==LISP Language Functions==<br />
These are some general CLISP functions that are useable in SWC-LISP, and not necessarily included in the dbg-env tables above.<br />
{|class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! SWC Lisp <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Evaluation<br />
! Default eval (if applicable)<br />
|-<br />
|car || ''list'' || The first element of the list. Aka 'First' || (car `(1 2 3)) -> 1 || n/a<br />
|-<br />
|cdr || ''list'' || A list of all the elements of the list, in order, except the first. AKA 'Rest' || (cdr `(1 2 3)) -> (2 3) || n/a<br />
|-<br />
|cons || ''expr1'' ''expr2'' || constructs a list from the two expressions provided. Typically used to prepend an element onto a list (push), using (cons atom1 list). Careful when consing atoms only. That creates a "dotted list" which can result in unexpected behaviour. If you want to make a list with just one element, either use (list atom) or `(atom), or (cons atom `()) aka (cons atom empty). || (cons 1 `(2 3)) -> (1 2 3) || n/a<br />
|-<br />
|list || ''expr1'' ''expr2'' ... ''exprN'' || Constructs a list out of atoms or lists, or I guess symbols. || (list 1 2 `(3)) -> (1 2 (3)) || n/a<br />
|-<br />
|empty? || ''list'' || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. || style="white-space: nowrap;"|(empty? `()) -> #t (empty? `(1)) -> #f || n/a<br />
|-<br />
|eq? || ''atom1'' ''atom2'' || Preposition: Are the two provided atoms equal? Unsure exactly which "eq" from LISP documentation this really is. Does not work for Lists. || (eq? 1 1) -> #t (eq? 1 2) -> #f ... || n/a<br />
|-<br />
|nth-of || ''list'' ''index#'' || aka "nth". Returns the nth element of list. Note: 0 is the first element. || (nth-of `(1 2 3) 0) -> 1; <br />
<br />
(nth-of `(1 2 (3 4)) 2 -> (3 4) <br />
|| n/a <br />
|-<br />
|floor<br />
|-<br />
|ceil<br />
|-<br />
|round<br />
|-<br />
|log<br />
|-<br />
|-exp<br />
|-<br />
|modulo<br />
|-<br />
|stochastic_round<br />
|}<br />
<br />
==How to Pass Parameters in Functions==<br />
Below you can see a simple example of creating a function accepting two parameters, and passing them.<br />
<br />
(defun (myfun a b)<br />
(ooc (concat "I do something with " a ", then I do something with " b)))<br />
<br />
(defun start<br />
(myfun "turkey" "salami"))<br />
<br />
Another example with numbers. This calculate the absolute of a number.<br />
(defun (abs x) <br />
(cond<br />
[(lt? x 0) (* x -1)]<br />
[#t x]))<br />
<br />
(defun start<br />
(say (concat "The absolute of 20 + -44 is " (abs (+ 20 -44)))))<br />
<br />
[[Category:Features]]<br />
[[Category:Advanced Activities]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3765SWC LISP2018-09-15T08:14:17Z<p>Ruben Wan: /* Conversational Functions */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.|| || || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
*[http://www.swcombine.com/rules/?Scripts Rules page on lisp]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP/Debugging_and_Errors&diff=3764SWC LISP/Debugging and Errors2018-09-14T23:24:28Z<p>Ruben Wan: /* Debugging Functions */</p>
<hr />
<div>==Debugging Functions==<br />
* <code>dbg-break</code> triggers an exception (ignoring the rest of the script) and print supplied values, for example <code>(dbg-break self character (+ 1 2))</code> will display info about the current entity, current character, and the number 3<br />
** note that if you put <code>(dbg-break)</code> in the global scope (a line on its own), it'll block the whole script at startup. Instead, you must use it inside another function, in the point where you want the script to stop.<br />
* <code>dbg-pp</code> prints values for debugging without triggering an exception (script continues), using the same semantics as <code>dbg-break</code><br />
* <code>dbg-env</code> dumps the entire symbol table (very large) and can be used to get basic information about the API to help with missing documentation<br />
* <code>dbg-rp</code> provides low-level view of data structures<br />
<br />
==Understanding Errors==<br />
Most often, if you get an error it is a problem of parenthesis. When you save the script, the parser checks only for matching parenthesis; however, if the total of open parenthesis matches the total of closed parenthesis, the parser reports no errors on saving.<br />
<br />
===Symbol [name] is not defined!===<br />
If you get this error while the script runs, it could mean that there are misplaced parenthesis. In this case, go through your script placing your cursor on the end parenthesis to see if everything is ok.<br />
<br />
If the error is not due to misplaced parenthesis, check that the name is not mispelt. If ok, check that the call to the function comes before the function called.<br />
<br />
===Symbol -> is not defined!===<br />
It is the easiest to fix. You've just written a "->" in an add-response function, between the end of text and the name of the function to go to. The old system used that symbol, but the new system need not that. Just remove that "->".<br />
<br />
A second case is if you've added a parameter to the describe function different from close. Example, the old 'left alignment keyword, now invalid.<br />
<br />
===Symbol is undefined and cannot be evaluated===<br />
You've probably forgotten to specify where to go after an add-response text. Simply add the name of the function to continue with.<br />
<br />
Mind the parenthesis if you have a concat function in add-response or other function with parameters. Example, this code is right:<br />
<br />
(defun start<br />
(say "Hello, how may I help you?")<br />
(cond<br />
[(eq? (get-race character) "Kuati") <br />
(add-response "Excuse me, your dress is very elegant. May I know what caste are you?" caste01)]<br />
[(not (eq? (get-race character) "Kuati")) <br />
(add-response (concat "I see you are a " (get-infofield self) ". What do you do, exactly?") do01) <br />
(add-response "Are you a real expert on ships?" expert01)<br />
(add-response "Very kind of you, but I am just browsing. No need for help." end01)]))<br />
<br />
but if you write the add-response with the concat function as <br />
(add-response (concat "I see you are a " (get-infofield self) ". What do you do, exactly?" do01))<br />
<br />
you get this type of error, because the closing parenthesis of the concat function must go after the string end and before the next-function-name parameter.<br />
<br />
====Symbol set-var is undefined and cannot be evaluated====<br />
The correct syntax is set-var! (with the 'bang') and not set-var or setvar. Check your syntax.<br />
<br />
===Invalid speech option selected===<br />
This is a generic error, meaning that any thing wrong in the next-function-name called by the user click may cause this error. A syntax error, a logic error... Below you find some examples. Note that this error appears when you try to click on an answer, therefore you should look for the function called by that answer. You can use the (dbg-xx) functions in the functions called by the add-action/add-response/add-text to check your code for unexpected evaluation results.<br />
<br />
* If you're trying to concatenate a text with a describe, you'll get this error. Example:<br /><br />
(say (concat "Well, another protocol droid you can see here is the SP-4. It is defined as an analysis droid and it uses the same chassis and many parts assembled in the cheaper PK-series worker droid. You cannot say that it is made to resemble its owner..." (describe "winks")))<br />
<br />
The solution is to put the describe in a single line, all alone, and remove the concat in the say function. `concat` only assembles several strings into one string. `describe` is a function that does not evaluate to a single string, and so concat cannot make proper use of it.<br />
<br />
* A conditional statement with a wrong use of keywords:<br />
(eq? (get-entity-faction character) "Galactic Empire")<br />
is bugged;<br />
(eq? (get-name (get-entity-faction character)) "Galactic Empire")<br />
is correct.<br />
<br />
* Adding a missing [#t] to a conditional statement.<br />
<br />
===Attempted to evaluate a literal value or a null: "somestring"===<br />
One possible case is that you are trying to call a function that needs a parameter from inside an add-response function. As of Y19D270, add-response can only call simple functions, without parameters.<br /><br />
In order to solve this problem, you should make an intermediate function. Example:<br />
(add-response "Please forward this parameter." (intermediate-fun))<br />
(defun intermediate-fun (get-parameter "Here is the parameter"))<br />
(defun (get-parameter thisparameter)<br />
code code code)<br />
<br />
===Not enough arguments supplied in function call===<br />
You have called a function that is expecting one or more parameters, but you have not specified any parameter.<br /><br />
Solution: add the parameters needed.<br />
<br />
===`set-var!` can only be called on *vars===<br />
wip<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3763SWC LISP2018-09-14T23:23:19Z<p>Ruben Wan: /* Variables */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Declarations==<br />
; (defun (foo bar (baz 1))<br /> code code code) : declares a function named ''foo'' with a required argument ''bar'' and an optional argument ''baz'' that defaults to 1 if not given.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.|| || || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3762SWC LISP2018-09-14T23:20:25Z<p>Ruben Wan: /* Definitions */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; hook : this allow asynchronous notification of events to different areas of code or LISP scripts (primarily in support of scripting responses to in-game events)<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.|| || || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3761SWC LISP2018-09-14T23:17:50Z<p>Ruben Wan: /* Others */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events (combat, travel, asset transfer, etc. for use with quests) and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.|| || || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3760SWC LISP2018-09-14T23:16:20Z<p>Ruben Wan: /* Conversational Functions */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. ''&close'' is boolean (defaults to true). If true, this will start a new paragraph.|| || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.|| || || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3759SWC LISP2018-09-14T23:09:54Z<p>Ruben Wan: /* Conditional Statements */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
==Others==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| create-hook|| ||Creates a hook that listen to specific in-game events and then call a lisp function || || ||<br />
|-<br />
| get-hook || ||Retrieves a hook by ID || || ||<br />
|-<br />
| delete-hook || ||Deletes an existing hook || || ||<br />
|-<br />
|}<br />
<br />
==Conversational Functions==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|say||message &close||Output: NPC "says" message. ''&close'' is boolean. If true, this will start a new paragraph.|| || || <br />
|- <br />
|describe||message &close||Output: NPC "describes" message. &close is boolean. If true, this will start a new paragraph.|| || || <br />
|- <br />
|ooc||message &close||Output: NPC "oocs" message. &close is boolean. If true, this will start a new paragraph.|| || || <br />
|- <br />
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting|| || || <br />
|- <br />
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting|| || || <br />
|- <br />
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting|| || || <br />
|- <br />
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.|| || || <br />
|- <br />
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. || || || <br />
|- <br />
|add-input||not implemented||Input: creates a text box for the user to type something in. In progress. || || || <br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3758SWC LISP2018-09-14T22:58:18Z<p>Ruben Wan: /* Lists */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
| sort || ||Numerical sorting of lists || || || <br />
|-<br />
| length || ||Returns the length of a list || || || <br />
|-<br />
| nth-of || ||Returns the nth element of a list || || || <br />
|-<br />
| sublist || ||Returns some number of elements from the middle of a list || || || <br />
|-<br />
| reverse || ||Reverses the elements in a list (at the top level) || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3757SWC LISP2018-09-14T22:52:15Z<p>Ruben Wan: /* Strings */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
| substr||string start &length ||Carves out a portion of a string. ''start'' is the position of the first character in the ''string'' you want to get, and ''length'' is the number of characters you want (default is to the end of the ''string''). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string ||1. (substr "I like cheese" 2)<br />2. (substr "I like cheese" 0 6)<br />3. (substr "I like cheese" -6) ||1. "like cheese"<br />2. "I like"<br />3. "cheese" || <br />
|-<br />
| strpos||string find start ||Looks in ''string'' for the string ''find'' starting to look at position ''start'', and returns the position in ''string'' where it finds it ||1. (strpos "I like cheese" "like")<br />2. (strpos "I like cheese" " ")<br />3. (strpos "I like cheese" " " 2) ||1. 2<br />2. 1<br />3. 6 (looking for a space but beginning after the first space) || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3756SWC LISP2018-09-14T22:40:23Z<p>Ruben Wan: /* Predicates */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|enum-valid? || || Tests a value for being part of an enum || || ||<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3755SWC LISP2018-09-14T22:38:55Z<p>Ruben Wan: /* Strings */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
| enum|| ||Retrieves a named value from a specific enum ||(enum 'entityType 'room) ||Retrieves the entity type value for rooms || <br />
|-<br />
| enum-values|| ||Retrieves all values from an enum || || || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP/Modules&diff=3754SWC LISP/Modules2018-09-14T17:31:28Z<p>Ruben Wan: </p>
<hr />
<div>See the Rules Page on SWC for additional explanations.<br />
<br />
Two new language constructs are <code>load</code> to use a module and <code>module-export</code> called from within a module (only useful here!) to declare a symbol to be made available outside the module. Modules have private internal state allowing for personal variables, etc.<br />
<br />
==swclib==<br />
(load "swclib")<br />
<br />
Contact: Selatos; Kay Dallben<br />
<br />
==funlib==<br />
(load "funlib")<br />
<br />
Contact: Selatos, Kay Dallben<br />
<br />
==mathematics==<br />
(load "mathematics")<br />
<br />
Contact: Kay Dallben<br />
<br />
==timelib==<br />
(load "timelib")<br />
<br />
Contact: Kay Dallben, mackaybre at gmail dot com<br />
<br />
==KayD-StringShortcuts==<br />
This library was removed as module and cannot be loaded. However, it is possible to use the functions by copying/pasting them.<br />
These functions insert appropriate pronoun string based on gender.<br />
<br />
(defun (female? (who self))<br />
(cond<br />
[(eq? (get-gender who) "female") #t]<br />
[#t #f]))<br />
<br />
(defun (male? (who self))<br />
(cond<br />
[(eq? (get-gender who) "male") #t]<br />
[#t #f]))<br />
<br />
(defun (HeShe? (who self))<br />
(cond<br />
[(female? who) "She"]<br />
[#t "He"]))<br />
<br />
(defun (heshe? (who self))<br />
(cond<br />
[(female? who) "she"]<br />
[#t "he"]))<br />
<br />
(defun (HerHis? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "His"]))<br />
<br />
(defun (herhis? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "his"]))<br />
<br />
(defun (HerHim? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "Him"]))<br />
<br />
(defun (herhim? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "him"]))<br />
<br />
Examples:<br />
* (say (concat "Yes, " (heshe (get-npc 54486)) " is pretty silly.")) -> "Yes, he is pretty silly."<br />
* (describe (concat (HerHis self) " gun points directly at you.")) -> Her gun points directly at you.<br />
* <b>heshe</b> <i>player-NPC-object</i><br />
* <b>HeShe</b> <i>player-NPC-object</i><br />
* <b>herhis</b> <i>player-NPC-object</i><br />
* <b>HerHis</b> <i>player-NPC-object</i><br />
* <b>herhim</b> <i>player-NPC-object</i><br />
* <b>HerHim</b> <i>player-NPC-object</i><br />
<br />
==Keyboard-Al Sayif==<br />
This Script Module (and paired NPC-Script requirements) enables a character-by-character input of a string into a script.<br />
<br />
NPC Script Requirements<br /><br />
;;;; ---------------------------------------------<br />
;; Corresponding Content for NPC/Entity<br />
<br />
(load "Keyboard-Al Sayif" "")<br />
(load "swclib")<br />
<br />
(bind-keyboard-mself (get-id self) 'npc)<br />
(bind-keyboard-convo say say-c describe describe-c ooc ooc-c)<br />
(bind-keyboard-responses add-action add-response add-text)<br />
(bind-keyboard-utils clear-window)<br />
<br />
(defun oncancel<br />
; Called when you hit the Cancel Button. Edit as needed.<br />
(ooc "Cancelled Keyboard Input."))<br />
<br />
(defun onfinish<br />
; called when user clicks the Enter button. Edit as needed.<br />
(clear-window)<br />
(say (myconcat "Well it's very nice to meet you, Mr. " (get-keyboard-response))))<br />
<br />
(bind-keyboard-callbacks onfinish oncancel)<br />
<br />
(defun start ;; Example to go straight into it. Edit as needed, or just use start-keyboard.<br />
(describe "Enter your input on the keypad. As you click the screen will update.")<br />
(start-keyboard))<br />
<br />
;;;; ---------------------------------------------<br />
<br />
===start-keyboard===<br />
* clears the window and starts the Keyboard Input script: Asks for input character by character. CAPS toggles between UPPERCASE and lowercase for letter, BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
===get-keyboard-response===<br />
* returns a string of the saved input from the keyboard.<br />
<br />
COMING SOON<sup>TM</sup><br />
<br />
===start-keypad===<br />
* clears the window and starts the Keypad Input script: Asks for input character by character (numbers 0 - 9 only). BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
Contact: Kay Dallben<br />
<br />
==input-general==<br />
Very similar to Keyboard, but this one allows you to send an arbitrary keyset (in the form of a list of strings) to be the options. This can be numbers only, letters, or even whole words. The Keyset must be a list of strings. Using return functions during the same session, you can obtain the results in either hyphen-separated String format or a list of entries.<br />
<br />
NPC Script Requirements<br /><br />
;;;; ---------------------------------------------<br />
;; Corresponding Content for NPC/Entity<br />
<br />
(load "input-general")<br />
(load "swclib")<br />
<br />
(bind-ninp-mself (get-id self) 'npc)<br />
(bind-ninp-convo say say-c describe describe-c ooc ooc-c)<br />
(bind-ninp-responses add-action add-response add-text)<br />
(bind-ninp-utils clear-window)<br />
<br />
(defun oncancel<br />
; Called when you hit the Cancel Button. Edit as needed.<br />
(ooc "Cancelled Input."))<br />
<br />
(defun onfinish<br />
; called when user clicks the Enter button. Edit as needed.<br />
(clear-window)<br />
(say (myconcat "The code you provided was: " (get-input-str))))<br />
<br />
(bind-ninp-callbacks onfinish oncancel)<br />
<br />
(defun start<br />
;; Example to go straight into it.<br />
(start-n-input `("Red" "Blue" "Yellow") "Provide a code sequence made up of the following colours:" ))<br />
<br />
;;;; ---------------------------------------------<br />
<br />
===start-n-input===<br />
* keyset (list) optional:::display-instructions(string) optional:::default-input(list)<br />
* clears the window and starts the input script with the list of available options.<br />
* allows user to input an unlimited amount of each key.<br />
* auto-adds the usual controlling options: BACK removes the last-entered key, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
* displays the provided instructions or "Input:" if nothing is provided.<br />
* starts with the provided default-input or `empty` if none provided.<br />
<br />
Example: (start-n-input `("Red" "Yellow" "Blue") "Create the desired code from the following possible choices:")<br />
<br />
===start-nex-input===<br />
* keyset (list) optional:::display-instructions(string) optional:::default-input(list)<br />
* clears the window and starts the input script with the list of available options.<br />
* the user may select each key in keyset only once. (IE: Use for non-repeating options, manual re-ordering of lists, etc.)<br />
* auto-adds the usual controlling options: BACK removes the last-entered key, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
* displays the provided instructions or "Input:" if nothing is provided.<br />
* starts with the provided default-input or `empty` if none provided.<br />
<br />
Example: (start-nex-input `("Red" "Yellow" "Blue") "Rank these colours in order from your most favourite to your least favourite:")<br />
<br />
===get-input-str===<br />
* returns a string of the saved input from the active session (IE: as it it shown during input)<br />
<br />
Example: Keyset: `("Red" "Yellow" "Blue") Input shows Blue-Blue-Yellow, will return: "Blue-Blue-Yellow")<br />
<br />
===get-input-list===<br />
* returns a list of the input (letter by letter or entry-by-entry) from the active session.<br />
<br />
Example: Keyset: `("Red" "Yellow" "Blue") Input shows Blue-Blue-Yellow, will return: `("Blue" "Blue" "Yellow")<br />
<br />
<br />
Contact: Kay Dallben<br />
<br />
==display-funs==<br />
A small module for the purposes of passing lists of say, ooc, describe, or lists of add-response, add-action, add-text statements to be evaluated. Should help in situations where you want to dynamically create options or speeches, for example multi-level option lists, etc.<br />
<br />
NB: Right now the batch say/etc. seems to break at about 90 elements, and that's really laggy so careful with your spam.<br />
<br />
;;;; ---------------------------------------------<br />
Functions available for use:<br />
<br />
===display-element disp-list===<br />
* disp-list is a list in the form of: <br />
(list stringCode (list say say-c describe describe-c ooc ooc-c))<br />
* I recommend setting up in your script module or NPC/Item script<br />
(defvar dfuns (list say say-c describe describe-c ooc ooc-c)) and/or a wrapper function<br />
(defun (disp string-code) (display-element (list string-code dfuns))<br />
* NB: not particularly useful except in conjunction with script-generated strings that might be of any of the forms.<br />
<br />
===disp-factory disp-strings funclist===<br />
* disp-strings is a list in the form (list "$s Say This" "$d Describe That" "$o OOC The other Thing" )<br />
* funclist is the dfuns mentioned above (list say say-c describe describe-c ooc ooc-c)<br />
<br />
NOTE: for both display-element and disp-factory, the strings use prefixes: "$s " is say, "$sc " is say-c, "$d " is describe, "$dc " is describe-c "$o " is ooc, "$oc " is ooc-c.<br />
<br />
<br />
===show-option optns===<br />
* displays the option.<br />
* options is a list of an option-list and the list of option funs (list add-response add-action add-text)<br />
* option-list example (list "^r I like cheese." likes-cheese), where `likes-cheese` is a no-parameter function defined in your script.<br />
* again, prefixes used are ^r ^a ^t for response, action, text respectively. Make sure you put a space between the prefix and the Label text.<br />
<br />
===option-factory list-of-option-lists optn-funs===<br />
* takes this list of option-lists and prints out all the options from same.<br />
* list-of-option-lists is a list of lists of option-lists.<br />
Example: (list `("^r I like cheese." ,likes-cheese) `("^a leave." ,leave))<br />
* again optn-funs is the (list add-response add-action add-text). defvar it for repetition or wrap the function in your script/SM.<br />
<br />
@TODO: create filtering/searching functions to parse incoming lists (especially of says, oocs, describes) and combine those that can be combined (ie if the list has a say followed by a say-c, they should be combined into a single 'say').<br /><br />
@TODO: further functions to assist in speedy creation of the requisite lists.<br />
<br />
Contact: Kay Dallben<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3753SWC LISP2018-09-14T17:26:36Z<p>Ruben Wan: /* Strings */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
| flash||type message ||Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. ''type'' is one of: 'good 'bad 'info, ''message'' is a string ||(flash 'good "You have received 25 XP for helping to free the Jawas" || || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3752SWC LISP2018-09-14T17:23:28Z<p>Ruben Wan: /* Definitions */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Variables==<br />
* *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Talk:SWC_LISP&diff=3751Talk:SWC LISP2018-09-14T17:19:10Z<p>Ruben Wan: </p>
<hr />
<div>same-time? and cmp-time do the same thing and are in the same library.<br />
<br />
rand-from-list Y16D1 and rand-from-list-unique are two different functions or the same?</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3750SWC LISP2018-09-14T17:18:31Z<p>Ruben Wan: /* Lists */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
| rand-from-list || || || || || <br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3749SWC LISP2018-09-14T17:16:51Z<p>Ruben Wan: /* Strings */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
| trim || ||?? || || ?? || <br />
|-<br />
|}<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=Talk:SWC_LISP&diff=3748Talk:SWC LISP2018-09-14T17:12:33Z<p>Ruben Wan: Created page with "same-time? and cmp-time do the same thing and are in the same library."</p>
<hr />
<div>same-time? and cmp-time do the same thing and are in the same library.</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP/Modules&diff=3747SWC LISP/Modules2018-09-14T17:07:24Z<p>Ruben Wan: /* input-general */</p>
<hr />
<div>See the Rules Page on SWC for additional explanations.<br />
<br />
==swclib==<br />
(load "swclib")<br />
<br />
Contact: Selatos; Kay Dallben<br />
<br />
==funlib==<br />
(load "funlib")<br />
<br />
Contact: Selatos, Kay Dallben<br />
<br />
==mathematics==<br />
(load "mathematics")<br />
<br />
Contact: Kay Dallben<br />
<br />
==timelib==<br />
(load "timelib")<br />
<br />
Contact: Kay Dallben, mackaybre at gmail dot com<br />
<br />
==KayD-StringShortcuts==<br />
This library was removed as module and cannot be loaded. However, it is possible to use the functions by copying/pasting them.<br />
These functions insert appropriate pronoun string based on gender.<br />
<br />
(defun (female? (who self))<br />
(cond<br />
[(eq? (get-gender who) "female") #t]<br />
[#t #f]))<br />
<br />
(defun (male? (who self))<br />
(cond<br />
[(eq? (get-gender who) "male") #t]<br />
[#t #f]))<br />
<br />
(defun (HeShe? (who self))<br />
(cond<br />
[(female? who) "She"]<br />
[#t "He"]))<br />
<br />
(defun (heshe? (who self))<br />
(cond<br />
[(female? who) "she"]<br />
[#t "he"]))<br />
<br />
(defun (HerHis? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "His"]))<br />
<br />
(defun (herhis? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "his"]))<br />
<br />
(defun (HerHim? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "Him"]))<br />
<br />
(defun (herhim? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "him"]))<br />
<br />
Examples:<br />
* (say (concat "Yes, " (heshe (get-npc 54486)) " is pretty silly.")) -> "Yes, he is pretty silly."<br />
* (describe (concat (HerHis self) " gun points directly at you.")) -> Her gun points directly at you.<br />
* <b>heshe</b> <i>player-NPC-object</i><br />
* <b>HeShe</b> <i>player-NPC-object</i><br />
* <b>herhis</b> <i>player-NPC-object</i><br />
* <b>HerHis</b> <i>player-NPC-object</i><br />
* <b>herhim</b> <i>player-NPC-object</i><br />
* <b>HerHim</b> <i>player-NPC-object</i><br />
<br />
==Keyboard-Al Sayif==<br />
This Script Module (and paired NPC-Script requirements) enables a character-by-character input of a string into a script.<br />
<br />
NPC Script Requirements<br /><br />
;;;; ---------------------------------------------<br />
;; Corresponding Content for NPC/Entity<br />
<br />
(load "Keyboard-Al Sayif" "")<br />
(load "swclib")<br />
<br />
(bind-keyboard-mself (get-id self) 'npc)<br />
(bind-keyboard-convo say say-c describe describe-c ooc ooc-c)<br />
(bind-keyboard-responses add-action add-response add-text)<br />
(bind-keyboard-utils clear-window)<br />
<br />
(defun oncancel<br />
; Called when you hit the Cancel Button. Edit as needed.<br />
(ooc "Cancelled Keyboard Input."))<br />
<br />
(defun onfinish<br />
; called when user clicks the Enter button. Edit as needed.<br />
(clear-window)<br />
(say (myconcat "Well it's very nice to meet you, Mr. " (get-keyboard-response))))<br />
<br />
(bind-keyboard-callbacks onfinish oncancel)<br />
<br />
(defun start ;; Example to go straight into it. Edit as needed, or just use start-keyboard.<br />
(describe "Enter your input on the keypad. As you click the screen will update.")<br />
(start-keyboard))<br />
<br />
;;;; ---------------------------------------------<br />
<br />
===start-keyboard===<br />
* clears the window and starts the Keyboard Input script: Asks for input character by character. CAPS toggles between UPPERCASE and lowercase for letter, BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
===get-keyboard-response===<br />
* returns a string of the saved input from the keyboard.<br />
<br />
COMING SOON<sup>TM</sup><br />
<br />
===start-keypad===<br />
* clears the window and starts the Keypad Input script: Asks for input character by character (numbers 0 - 9 only). BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
Contact: Kay Dallben<br />
<br />
==input-general==<br />
Very similar to Keyboard, but this one allows you to send an arbitrary keyset (in the form of a list of strings) to be the options. This can be numbers only, letters, or even whole words. The Keyset must be a list of strings. Using return functions during the same session, you can obtain the results in either hyphen-separated String format or a list of entries.<br />
<br />
NPC Script Requirements<br /><br />
;;;; ---------------------------------------------<br />
;; Corresponding Content for NPC/Entity<br />
<br />
(load "input-general")<br />
(load "swclib")<br />
<br />
(bind-ninp-mself (get-id self) 'npc)<br />
(bind-ninp-convo say say-c describe describe-c ooc ooc-c)<br />
(bind-ninp-responses add-action add-response add-text)<br />
(bind-ninp-utils clear-window)<br />
<br />
(defun oncancel<br />
; Called when you hit the Cancel Button. Edit as needed.<br />
(ooc "Cancelled Input."))<br />
<br />
(defun onfinish<br />
; called when user clicks the Enter button. Edit as needed.<br />
(clear-window)<br />
(say (myconcat "The code you provided was: " (get-input-str))))<br />
<br />
(bind-ninp-callbacks onfinish oncancel)<br />
<br />
(defun start<br />
;; Example to go straight into it.<br />
(start-n-input `("Red" "Blue" "Yellow") "Provide a code sequence made up of the following colours:" ))<br />
<br />
;;;; ---------------------------------------------<br />
<br />
===start-n-input===<br />
* keyset (list) optional:::display-instructions(string) optional:::default-input(list)<br />
* clears the window and starts the input script with the list of available options.<br />
* allows user to input an unlimited amount of each key.<br />
* auto-adds the usual controlling options: BACK removes the last-entered key, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
* displays the provided instructions or "Input:" if nothing is provided.<br />
* starts with the provided default-input or `empty` if none provided.<br />
<br />
Example: (start-n-input `("Red" "Yellow" "Blue") "Create the desired code from the following possible choices:")<br />
<br />
===start-nex-input===<br />
* keyset (list) optional:::display-instructions(string) optional:::default-input(list)<br />
* clears the window and starts the input script with the list of available options.<br />
* the user may select each key in keyset only once. (IE: Use for non-repeating options, manual re-ordering of lists, etc.)<br />
* auto-adds the usual controlling options: BACK removes the last-entered key, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
* displays the provided instructions or "Input:" if nothing is provided.<br />
* starts with the provided default-input or `empty` if none provided.<br />
<br />
Example: (start-nex-input `("Red" "Yellow" "Blue") "Rank these colours in order from your most favourite to your least favourite:")<br />
<br />
===get-input-str===<br />
* returns a string of the saved input from the active session (IE: as it it shown during input)<br />
<br />
Example: Keyset: `("Red" "Yellow" "Blue") Input shows Blue-Blue-Yellow, will return: "Blue-Blue-Yellow")<br />
<br />
===get-input-list===<br />
* returns a list of the input (letter by letter or entry-by-entry) from the active session.<br />
<br />
Example: Keyset: `("Red" "Yellow" "Blue") Input shows Blue-Blue-Yellow, will return: `("Blue" "Blue" "Yellow")<br />
<br />
<br />
Contact: Kay Dallben<br />
<br />
==display-funs==<br />
A small module for the purposes of passing lists of say, ooc, describe, or lists of add-response, add-action, add-text statements to be evaluated. Should help in situations where you want to dynamically create options or speeches, for example multi-level option lists, etc.<br />
<br />
NB: Right now the batch say/etc. seems to break at about 90 elements, and that's really laggy so careful with your spam.<br />
<br />
;;;; ---------------------------------------------<br />
Functions available for use:<br />
<br />
===display-element disp-list===<br />
* disp-list is a list in the form of: <br />
(list stringCode (list say say-c describe describe-c ooc ooc-c))<br />
* I recommend setting up in your script module or NPC/Item script<br />
(defvar dfuns (list say say-c describe describe-c ooc ooc-c)) and/or a wrapper function<br />
(defun (disp string-code) (display-element (list string-code dfuns))<br />
* NB: not particularly useful except in conjunction with script-generated strings that might be of any of the forms.<br />
<br />
===disp-factory disp-strings funclist===<br />
* disp-strings is a list in the form (list "$s Say This" "$d Describe That" "$o OOC The other Thing" )<br />
* funclist is the dfuns mentioned above (list say say-c describe describe-c ooc ooc-c)<br />
<br />
NOTE: for both display-element and disp-factory, the strings use prefixes: "$s " is say, "$sc " is say-c, "$d " is describe, "$dc " is describe-c "$o " is ooc, "$oc " is ooc-c.<br />
<br />
<br />
===show-option optns===<br />
* displays the option.<br />
* options is a list of an option-list and the list of option funs (list add-response add-action add-text)<br />
* option-list example (list "^r I like cheese." likes-cheese), where `likes-cheese` is a no-parameter function defined in your script.<br />
* again, prefixes used are ^r ^a ^t for response, action, text respectively. Make sure you put a space between the prefix and the Label text.<br />
<br />
===option-factory list-of-option-lists optn-funs===<br />
* takes this list of option-lists and prints out all the options from same.<br />
* list-of-option-lists is a list of lists of option-lists.<br />
Example: (list `("^r I like cheese." ,likes-cheese) `("^a leave." ,leave))<br />
* again optn-funs is the (list add-response add-action add-text). defvar it for repetition or wrap the function in your script/SM.<br />
<br />
@TODO: create filtering/searching functions to parse incoming lists (especially of says, oocs, describes) and combine those that can be combined (ie if the list has a say followed by a say-c, they should be combined into a single 'say').<br /><br />
@TODO: further functions to assist in speedy creation of the requisite lists.<br />
<br />
Contact: Kay Dallben<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP/Modules&diff=3746SWC LISP/Modules2018-09-14T17:02:52Z<p>Ruben Wan: </p>
<hr />
<div>See the Rules Page on SWC for additional explanations.<br />
<br />
==swclib==<br />
(load "swclib")<br />
<br />
Contact: Selatos; Kay Dallben<br />
<br />
==funlib==<br />
(load "funlib")<br />
<br />
Contact: Selatos, Kay Dallben<br />
<br />
==mathematics==<br />
(load "mathematics")<br />
<br />
Contact: Kay Dallben<br />
<br />
==timelib==<br />
(load "timelib")<br />
<br />
Contact: Kay Dallben, mackaybre at gmail dot com<br />
<br />
==KayD-StringShortcuts==<br />
This library was removed as module and cannot be loaded. However, it is possible to use the functions by copying/pasting them.<br />
These functions insert appropriate pronoun string based on gender.<br />
<br />
(defun (female? (who self))<br />
(cond<br />
[(eq? (get-gender who) "female") #t]<br />
[#t #f]))<br />
<br />
(defun (male? (who self))<br />
(cond<br />
[(eq? (get-gender who) "male") #t]<br />
[#t #f]))<br />
<br />
(defun (HeShe? (who self))<br />
(cond<br />
[(female? who) "She"]<br />
[#t "He"]))<br />
<br />
(defun (heshe? (who self))<br />
(cond<br />
[(female? who) "she"]<br />
[#t "he"]))<br />
<br />
(defun (HerHis? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "His"]))<br />
<br />
(defun (herhis? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "his"]))<br />
<br />
(defun (HerHim? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "Him"]))<br />
<br />
(defun (herhim? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "him"]))<br />
<br />
Examples:<br />
* (say (concat "Yes, " (heshe (get-npc 54486)) " is pretty silly.")) -> "Yes, he is pretty silly."<br />
* (describe (concat (HerHis self) " gun points directly at you.")) -> Her gun points directly at you.<br />
* <b>heshe</b> <i>player-NPC-object</i><br />
* <b>HeShe</b> <i>player-NPC-object</i><br />
* <b>herhis</b> <i>player-NPC-object</i><br />
* <b>HerHis</b> <i>player-NPC-object</i><br />
* <b>herhim</b> <i>player-NPC-object</i><br />
* <b>HerHim</b> <i>player-NPC-object</i><br />
<br />
==Keyboard-Al Sayif==<br />
This Script Module (and paired NPC-Script requirements) enables a character-by-character input of a string into a script.<br />
<br />
NPC Script Requirements<br /><br />
;;;; ---------------------------------------------<br />
;; Corresponding Content for NPC/Entity<br />
<br />
(load "Keyboard-Al Sayif" "")<br />
(load "swclib")<br />
<br />
(bind-keyboard-mself (get-id self) 'npc)<br />
(bind-keyboard-convo say say-c describe describe-c ooc ooc-c)<br />
(bind-keyboard-responses add-action add-response add-text)<br />
(bind-keyboard-utils clear-window)<br />
<br />
(defun oncancel<br />
; Called when you hit the Cancel Button. Edit as needed.<br />
(ooc "Cancelled Keyboard Input."))<br />
<br />
(defun onfinish<br />
; called when user clicks the Enter button. Edit as needed.<br />
(clear-window)<br />
(say (myconcat "Well it's very nice to meet you, Mr. " (get-keyboard-response))))<br />
<br />
(bind-keyboard-callbacks onfinish oncancel)<br />
<br />
(defun start ;; Example to go straight into it. Edit as needed, or just use start-keyboard.<br />
(describe "Enter your input on the keypad. As you click the screen will update.")<br />
(start-keyboard))<br />
<br />
;;;; ---------------------------------------------<br />
<br />
===start-keyboard===<br />
* clears the window and starts the Keyboard Input script: Asks for input character by character. CAPS toggles between UPPERCASE and lowercase for letter, BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
===get-keyboard-response===<br />
* returns a string of the saved input from the keyboard.<br />
<br />
COMING SOON<sup>TM</sup><br />
<br />
===start-keypad===<br />
* clears the window and starts the Keypad Input script: Asks for input character by character (numbers 0 - 9 only). BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
Contact: Kay Dallben<br />
<br />
==input-general==<br />
Very similar to Keyboard, but this one allows you to send an arbitrary keyset (in the form of a list of strings) to be the options. This can be numbers only, letters, or even whole words. The Keyset must be a list of strings. Using return functions during the same session, you can obtain the results in either hyphen-separated String format or a list of entries.<br />
<br />
NPC Script Requirements<br /><br />
;;;; ---------------------------------------------<br />
;; Corresponding Content for NPC/Entity<br />
<br />
(load "input-general")<br />
(load "swclib")<br />
<br />
(bind-ninp-mself (get-id self) 'npc)<br />
(bind-ninp-convo say say-c describe describe-c ooc ooc-c)<br />
(bind-ninp-responses add-action add-response add-text)<br />
(bind-ninp-utils clear-window)<br />
<br />
(defun oncancel<br />
; Called when you hit the Cancel Button. Edit as needed.<br />
(ooc "Cancelled Input."))<br />
<br />
(defun onfinish<br />
; called when user clicks the Enter button. Edit as needed.<br />
(clear-window)<br />
(say (myconcat "The code you provided was: " (get-input-str))))<br />
<br />
(bind-ninp-callbacks onfinish oncancel)<br />
<br />
(defun start<br />
;; Example to go straight into it.<br />
(start-n-input `("Red" "Blue" "Yellow") "Provide a code sequence made up of the following colours:" ))<br />
<br />
;;;; ---------------------------------------------<br />
<br />
===start-n-input===<br />
* keyset (list) optional:::display-instructions(string) optional:::default-input(list)<br />
* clears the window and starts the input script with the list of available options.<br />
* allows user to input an unlimited amount of each key.<br />
* auto-adds the usual controlling options: BACK removes the last-entered key, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
* displays the provided instructions or "Input:" if nothing is provided.<br />
* starts with the provided default-input or `empty` if none provided.<br />
<br />
Example: (start-n-input `("Red" "Yellow" "Blue") "Create the desired code from the following possible choices:")<br />
<br />
===start-nex-input===<br />
* keyset (list) optional:::display-instructions(string) optional:::default-input(list)<br />
* clears the window and starts the input script with the list of available options.<br />
* the user may select each key in keyset only once. (IE: Use for non-repeating options, manual re-ordering of lists, etc.)<br />
* auto-adds the usual controlling options: BACK removes the last-entered key, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
* displays the provided instructions or "Input:" if nothing is provided.<br />
* starts with the provided default-input or `empty` if none provided.<br />
<br />
Example: (start-nex-input `("Red" "Yellow" "Blue") "Rank these colours in order from your most favourite to your least favourite:")<br />
<br />
===get-input-str===<br />
* returns a string of the saved input from the active session (IE: as it it shown during input)<br />
<br />
Example: Keyset: `("Red" "Yellow" "Blue") Input shows Blue-Blue-Yellow, will return: "Blue-Blue-Yellow")<br />
<br />
===get-input-list===<br />
* returns a list of the input (letter by letter or entry-by-entry) from the active session.<br />
<br />
Example: Keyset: `("Red" "Yellow" "Blue") Input shows Blue-Blue-Yellow, will return: `("Blue" "Blue" "Yellow")<br />
<br />
<br />
Contact: Kay Dallben<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP&diff=3745SWC LISP2018-09-14T16:50:54Z<p>Ruben Wan: /* Time Related Functions */</p>
<hr />
<div>Main page - trying to reorganise the LISP content<br />
<br />
<br />
SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.<br />
<br />
==Definitions==<br />
Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the ''first'' thing. 2 is the ''second'' thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.<br />
<br />
; atom : a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number, <br />
; boolean : Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as '''''predicates''''', and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?<br />
; define : in the sense of LISP, this means to formally tell the script what you want a given ''symbol'' to evaluate to. You use two functions for this: ''defvar'' for variables and ''defun'' for functions.<br />
; element : We often refer to each 'thing' inside a list as an ''element''. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it. <br />
; evaluate : More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"<br />
; functions : Instructions to the interpreter on what to do. You define these using ''defun'' telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (''parameters''), what temporary symbols you will use to refer to each parameter ("''local variables''"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.<br />
; lambda functions : They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.<br />
; list : a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists. <br />
; parameter : a piece of data you feed to a function, upon which it operates. Also known as ''input''. These are often listed as an expected type - for example ''defvar'' expects a ''symbol'' and a ''value'', while ''say'' expects a ''string''.<br />
; quoting : Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to ''code mode''. On the other hand, stuff written in ''data mode'' is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The '''single quote '''' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).<br />
; quasiquoting : This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a ''backquote'' [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the ''comma'' character, to flip back into code mode. Example: <code>`(a b ,character)</code> produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.<br />
; s-expression : a general term that means an atom or a grouping of atoms called a ''list''.<br />
; scope : Really we mean ''lexical scope'', which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.<br />
; session : a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.<br />
; string : A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".<br />
; symbol : looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.<br />
; variables : As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.<br />
<br />
==Predicates==<br />
The following table lists functions that return either #t or #f. <br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|is-unharmed?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "unharmed"||(is-unharmed? character)||#t||(load "swclib")<br />
|- <br />
|is-slightly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "slightly wounded"||(is-slightly-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "wounded"||(is-wounded? character)||#f||(load "swclib")<br />
|- <br />
|is-badly-wounded?||player-NPC-object||Returns true if player-NPC-object's HP-Status-Text is "badly wounded"||(is-badly-wounded? character)||#f||(load "swclib")<br />
|-<br />
|in-same-faction?||entityA entityB||Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB))||(in-same-faction? )||#t||(load "swclib")<br />
|-<br />
|in-container?||object container||Returns true if object is inside container||(n-container? hilt toolkit)||#t||(load "swclib")<br />
|-<br />
|is-ally?||player-NPC-object||Returns true if NPC/PC is IFF friendly (defaults to self)||(is-ally? self)||#t||<br />
|-<br />
|is-enemy?||player-NPC-object||Returns true if NPC/PC is IFF enemy (defaults to self)||(is-enemy? self)||#f||<br />
|-<br />
|is-neutral?||player-NPC-object||Returns true if NPC/PC is IFF neutral (defaults to self)||(is-neutral? self)||#f||<br />
|-<br />
|is-owner?||player||Returns true if character is the owner of the NPC||(is-owner? character)||#t||<br />
|-<br />
|is-commander?||player||Returns true if character is the commander of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-manager?||player||Returns true if character is the manager of the NPC ||(is-manager? character)||#t||<br />
|-<br />
|is-pilot?|| player ||Returns true if character is the owner of the NPC ||(is-pilot? character)||#t||<br />
|- <br />
|is-supervisor? ||player||Returns true if character is the supervisor of the NPC||(is-supervisor?)||#t|| <br />
|-<br />
|is-freelancer?|| player ||Returns true if the character is a freelancer||(is-freelancer? character)||#t||<br />
|-<br />
|is-traveling?|| player ||Checks if the character is traveling or not ||(is-traveling? character)||#t||<br />
|-<br />
|in-room?|| entity-object ||Checks if the entity is in any room at all, as opposed to outside on the surface ||(in-room? entity-object)||#t||<br />
|- <br />
|faction-owned?||entity||Returns true if the entity is owned by a faction ||(faction-owned? self)||#t|| <br />
|-<br />
|empty? ||list || checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. ||1. (empty? `())<br />2. (empty? `(1))||1. #t<br />2. #f ||<br />
|-<br />
|in? ||needle haystack||Returns true if one or more of the elements of ''haystack'' is equal to ''needle''. ''needle'' is an atom and ''haystack'' is a list of atoms ||(in? 3 (list 1 'a 6 3 'u)) ||#t ||(load "funlib")<br />
|-<br />
|sublists-empty? ||list-of-lists || Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level || || ||(load "funlib")<br />
|-<br />
|earlier? ||timeA timeB || Returns true if ''timeA'' is less than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|later? ||timeA timeB || Returns true if ''timeA'' is greater than ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|-<br />
|same-time? ||timeA timeB || Returns true if ''timeA'' is equal to ''timeB''. timeA and timeB are two time objects || || ||(load "timelib")<br />
|}<br />
<br />
==Operators==<br />
===Arithmetic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| +||number1 number2 &numberN||Adds numbers together||(+ 5 2)||7|| <br />
|- <br />
| -||number1 number2 &numberN||Subtracts numbers||(- 5 2)||3|| <br />
|- <br />
|*||number1 number2 &numberN||Multiplies numbers||(* 5 2)||10|| <br />
|- <br />
|/||number1 number2||Divides numbers||(/ 10 2)||5|| <br />
|-<br />
|abs||number||Returns the absolute value of number||(abs -10)||10||(load "mathematics")<br />
|-<br />
|power||number exponent||Returns the value of number<sup>exponent</sup>||(power 2 3)||8||(load "mathematics")<br />
|-<br />
|minof||list-of-numbers||Returns the minimum value from a list of numbers||(minof '(2 3 7 9 1 18))||1||(load "mathematics")<br />
|-<br />
|maxof||list-of-numbers||Returns the maximum value from a list of numbers||(maxof '(2 3 27 9 1 18))||27||(load "mathematics")<br />
|-<br />
|neg?||number||Returns true if number is negative, nil if positive||(neg? -1)||#t||(load "mathematics")<br />
|-<br />
|pos?||number||Returns true if number is positive, nil if negative||(pos? 1)||#t||(load "mathematics")<br />
|-<br />
|zero?||number||Returns true if number is 0, nil if otherwise||(zero? 0)||#t||(load "mathematics")<br />
|-<br />
|factorial||number||Returns !number||(factorial 5)||120||(load "mathematics")<br />
|-<br />
|common-number-format||number||Returns a string with commas separating the thousands||(common-number-format 10000.51)||"10,000.51"||(load "mathematics")<br />
|-<br />
|add-leading-zeros||number &HowManyDigits||Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1||1. (add-leading-zeros 3)<br />2. (add-leading-zeros 30)<br />3. (add-leading-zeros 3 2)<br />4. (add-leading-zeros 30 2)||1. "03"<br />2. "30"<br />3. "003"<br />4. "030"||(load "mathematics")<br />
|-<br />
|}<br />
<br />
===Comparison Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|ge?||number1 number2||Is number1 equal to or greater than number2?||(ge? 5 2)||#t|| <br />
|- <br />
|le?||number1 number2||Is number1 equal to or less than number2?||(le? 5 2)||#f|| <br />
|- <br />
|gt?||number1 number2||Is number1 greater than number2?||(gt? 5 2)||#t|| <br />
|- <br />
|lt?||number1 number2||Is number1 less than number2?||(lt? 5 2)||#f|| <br />
|-<br />
|eq? || atom1 atom2 || Returns true if the two provided atoms are equal. Does not work for Lists. ||1. (eq? 1 1)<br />2. (eq? 1 2)||1. #t<br />2. #f||<br />
|-<br />
|neq?||atom1 atom2||Returns true if atom 1 is not equal to atom 2||(neq? 1 2)||#t||(load "funlib") <br />
|-<br />
|eq-lists?||listA listB||Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists||1. (eq-lists? '(a b c) '(d e f))<br />2. (eq-lists? '(a b c) '(a b c))<br />3. (eq-lists? '( '(a) b c))||1. #f<br />2. #f<br />3. Error||(load "funlib") <br />
|-<br />
|}<br />
<br />
===Logic Operators===<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|and||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if all exprs are true||(and? #t #f)||#f|| <br />
|- <br />
|or||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns true if at least one expr is true||(or #t #f)||#t|| <br />
|- <br />
|not||boolean-expression1 boolean-expression2 &boolean-expressionN||Returns the opposite value||(not #t)||#f|| <br />
|- <br />
|}<br />
<br />
==Getters==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|get-name||player-NPC-object|| Returns the name of the entity ||1. (get-name self)<br />2. (get-name (get-entity-faction character))<br />3. (get-name (get-container self))<br />4. (get-name (get-vehicle 1150488))||1. Johnny Walker<br />2. New Republic (empty string if Freelance<br />3. Tydirium (Current container name, e.g. the ship or vehicle standing in)<br />4. My vehicle|| <br />
|-<br />
|get-race|| player-NPC ||Returns the PC/NPC's race as string ||(get-race self)||Nautolan ||<br />
|-<br />
|get-infofield||player-NPC ||Returns the string of the first infofield of PC/NPC's||1. (get-infofield self)<br />2. (get-infofield (get-npc 111548)) ||1. Master Carpenter<br />2. empty string ||<br />
|-<br />
|get-infofield2||player-NPC ||Returns the string of the 2nd infofield of PC/NPC's||1. (get-infofield2 self)<br />2. (get-infofield2 (get-character "Kay Dallben")) ||1. O-4<br />2. ||<br />
|-<br />
|get-infofield3||player-NPC ||Returns the string of the 3rd infofield of PC/NPC's||1. (get-infofield3 self)<br />2. (get-infofield3 (get-character "Kay Dallben")) ||1. Inactive<br />2. ||<br />
|-<br />
|get-gender||player-NPC ||Returns the PC/NPC's gender as a string ||(get-gender self)||Male ||<br />
|-<br />
|get-formal||player-NPC ||Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) ||(get-formal (get-character "Kay Dallben")) ||Sir ||<br />
|-<br />
|get-entity-faction|| player-NPC ||Returns the PC/NPC's current faction ||(get-entity-faction character)||Galactic Empire ||<br />
|-<br />
|get-destination|| entity ||Returns the destination name ||(get-destination entity)||"Corellia sector" (if deep space) <br /> "Corellia system" (if heading to that system) <br /><br />
"Corellia planet" (if heading in sublight) <br /> "Atmosphere (3,4) of Corellia" (if heading in atmo) <br /> "Ground (3,4) of city Cityname on Corellia" (if heading to ground in city) <br /> "Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)<br />
|-<br />
|get-eta|| entity ||Returns the ETA for current travel ||(get-eta entity)||3 days, 24 hours and 5 minutes ||<br />
|-<br />
|get-entity-type-name|| entity ||Returns the name of the type of the entity|| (get-entity-type-name (get-container self)) ||Lambda Shuttle||<br />
|-<br />
|get-type|| entity-object ||Returns the current container entity type, e.g. the ship, vehicle, city, planet, station ||(get-type entity-object)||Ship, Vehicle, City, Planet, Space Station||<br />
|- <br />
|get-entity-type-id||name||Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station}||(get-entity-type-id 'Planet) -> ||n/a|| <br />
|- <br />
|get-type-type||typeID entityType||returns a full TYPE|| (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298) || || <br />
|- <br />
|get-creature-type||typeID||returns the type of Creature|| (get-creature-type 175) returns the type for an Eye-Snatcher || || <br />
|- <br />
|get-droid-type ||typeID|| returns the type of Droid||(get-droid-type 14) gets the droid type obj for Pit Droids|| || <br />
|- <br />
|get-item-type ||typeID|| returns the type of Item||(get-item-type 298) returns the type of a Focusing Crystal || || <br />
|- <br />
|get-npc-type||typeID||returns the type of NPC||(get-npc-type NUM) returns the type for a NPC of typeid NUM|| ||needs testing<br />
|- <br />
|get-type-of||entity||returns the type object for the entity||(get-type-of self) could return the type for a Quest NPC (if self is a quest npc)|| ||<br />
|- <br />
|get-npc-owner || ||returns the "NPC Owner" object|| || ||useful for an is-unclaimed? check.<br />
|- <br />
|get-hostile-owner|| ||returns the "Hostile Owner" object|| || ||ie checks if it is a spawned Bandit/Creature<br />
|- <br />
|get-market-owner|| ||returns the "Market Owner" object || || || <br />
|- <br />
|get-character || name ||entity-object for character "name"||(get-character "Kay Dallben")||n/a|| <br />
|- <br />
|get-faction||name||faction-object for faction "name"||(get-faction "Darkness") ||n/a|| <br />
|- <br />
|get-npc||id||npc-object for NPC with ID id||(get-npc 155408)||n/a|| <br />
|- <br />
|get-quest||id||quest-object for quest with ID id||(get-quest 4408)||n/a|| <br />
|- <br />
|get-item||id||item-object for item with ID id||(get-item 481099)||n/a|| <br />
|- <br />
|get-ship||id||ship-object for ship with ID id||(get-ship 448088)||n/a|| <br />
|- <br />
|get-vehicle||id||vehicle-object for vehicle with ID id||(get-vehicle 46846816)||n/a|| <br />
|- <br />
|get-room||id|| room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers.||(get-room 4478)|| n/a|| <br />
|- <br />
|get-id ||entity||ID for the entity||(get-id (get-npc 100)) -> 100||n/a || <br />
|- <br />
|get-hp-status-text||entity||string of the hp-status-text {unharmed, slightly-wounded, etc.}||(get-hp-status-text self) ||n/a|| <br />
|-<br />
|get-owner||entity||owner object of entity||(get-owner self)-> Kay Dallben|| || <br />
|- <br />
|get-container||entity||entity-object for container of entity. || (get-container self) || n/a || <br />
|- <br />
|get-location||entity||String of location (currently including hyperlinks) if viewable without godmoding.|| || ||needs testing<br />
|-<br />
|get-storageform||entity get-entity-type-name||Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).<br /> NOTE: If you use this in a script module you must bind the function (get-entity-type-name) ||(get-storageform (get-npc 22048668) get-entity-type-name) ||'("NPC" "Quest NPC" 22048668 "Vash Thompson") ||(load "swclib")<br />
|-<br />
|get-entity-from-storageform||storageform||Returns the entity object described in storageform. ''storageform'' is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson")|| || ||(load "swclib")<br />
|-<br />
|get-first-n||n list||Returns the first ''n'' elements of ''list''. If ''n'' > (length ''list'') it returns the whole list. ''n'' is an integer and ''list'' is a list ||(get-first-n 3 '(a b c d e f g h i j)) ||'(a b c) ||(load "funlib")<br />
|-<br />
|get-name-typeof||entity-type||Returns just the Name component of the ''entity-type''. ''entity-type'' is a type, i.e. what you can get from (get-typeof ''entity'') ||(defvar held-in-hand (get-item FocusingCrystalid))<br />(get-name-typeof (get-typeof held-in-hand)) ||"Focusing Crystal" ||(load "funlib")<br />
|-<br />
|get-nth||haystack nth||Returns the ''nth'' element of ''haystack'' using <code>car</code> and <code>cdr</code> only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth ||(get-nth ?? ||?? ||(load "funlib")<br />
|-<br />
|}<br />
<br />
==Functions for SWC Database==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
|faction-type|| player-NPC ||Character's faction's type || (faction-type (get-entity-faction character)) || Mining (Empty string if freelance) ||<br />
|-<br />
|faction-leader|| player-NPC ||Character's faction's leaders name || (faction-leader (get-entity-faction character)) || Ellias (Empty String if freelance) ||<br />
|-<br />
|faction-website || player-NPC ||Character's faction's website URL ||(faction-website (get-entity-faction character)) || http://swcombine.com (Link) (Empty string if freelance) ||<br />
|-<br />
|city-name || player-NPC ||Current city name ||(city-name character) || City 327 ||<br />
|-<br />
|planet-name || player-NPC ||Current planet name ||(planet-name character)|| Glee Anselm ||<br />
|-<br />
|system-name|| player-NPC ||Current system name ||(system-name character)|| Danju ||<br />
|-<br />
|sector-name|| player-NPC ||Current sector name ||(sector-name character)||Tapani ||<br />
|-<br />
|}<br />
<br />
==Time Related Functions==<br />
Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).<br />
<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| cgt-year|| n.a. ||Gets current CGT year ||(cgt-year)|| 12 || <br />
|-<br />
| cgt-day|| n.a. ||Gets current CGT day ||(cgt-day)||183 || <br />
|-<br />
| cgt-hour|| n.a. ||Gets current CGT hour ||(cgt-hour)||23 || <br />
|-<br />
| cgt-minute|| n.a. ||Gets current CGT minutes ||(cgt-minute)||59 || <br />
|-<br />
| cgt-second|| n.a. ||Gets current CGT seconds||(cgt-second)||59 || <br />
|-<br />
| timeofday|| n.a. ||Gets current phase of day ||(timeofday)||Morning, Afternoon, Evening ||<br />
|-<br />
| now-time|| n.a. ||Returns the 'time' object for Now ||(now-time)|| || (load "timelib")<br />
|-<br />
| now-seconds|| n.a. ||Returns the seconds for Now ||(now-seconds)|| || (load "timelib")<br />
|-<br />
| now-plus-days|| amount ||Add amount to Now in days ||(now-plus-days 3)|| a time object that is 3 days from Now|| (load "timelib")<br />
|-<br />
| now-plus-hours|| amount ||Add amount to Now in hours||(now-plus-hours 5)|| a time object that is 5 hours from Now || (load "timelib")<br />
|-<br />
| now-plus-minutes|| amount ||Add amount to Now in minutes ||(now-plus-minutes 18)|| a time object that is 18 minutes from Now || (load "timelib")<br />
|-<br />
| now-plus-seconds|| amount ||Add amount to Now in seconds||(now-plus-seconds 55)|| a time object that is 55 seconds from Now || (load "timelib")<br />
|-<br />
| timer-end-time|| amount-or-time &ydhms start-time ||Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. ||1. (timer-end-time 30)<br />2. (timer-end-time 5 'h '(17 192 13 57 05))||1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution<br />2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05 || (load "timelib")<br />
|-<br />
| time-to-string|| time &format||Converts a time object to a string. format defaults to 'YDHMS ||If time '(17 192 18 20 15) then:<br />1. (time-to-string time 'YDHMS)<br />2. (time-to-string time 'YYDDHHMMSS)<br />3. (time-to-string time 'YsDsHsMsSs)|| 1. "Y17 D192 18:20:15"<br />2. "Year 17 Day 192 18:20:15"<br />3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"|| (load "timelib")<br />
|-<br />
| cmp-time|| timeA timeB ||Basic comparison of two time objects. Returns true if equal ||(cmp-time)|| || (load "timelib")<br />
|-<br />
| fix-improper-time|| time ||Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.<br />-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365 || || || (load "timelib")<br />
|-<br />
| add-n|| time amount ||Adds that amount of ''n'' to the ''time''. ''n'' is any of seconds mins hrs days years || || || (load "timelib")<br />
|-<br />
| add-times|| timeA timeB ||Returns the time object which is the sum of ''timeA'' and ''timesB''. Proper format. || || || (load "timelib")<br />
|-<br />
| add-ydhms-to|| time ydhms amount ||All-encompassing time-addition function. Adds ''amount'' 'y 'd 'h 'm or 's to ''time''. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ''ydhms'' || || || (load "timelib")<br />
|-<br />
| sub-times|| timeA timeB ||Returns the time object which is ''timeA'' minus ''timesB'' || || || (load "timelib")<br />
|-<br />
| diff-times|| timeA timeB ||Returns the time object which is the smalles difference of ''timeA'' and ''timeB'' || || || (load "timelib")<br />
|-<br />
| to-seconds|| time ||Converts ''time'' into seconds || || || (load "timelib")<br />
|-<br />
| to-time|| seconds ||Converts ''seconds'' into time || || || (load "timelib")<br />
|-<br />
|}<br />
<br />
==Strings==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| abc ||n.a.||List of strings comprising the alphabet, lowercase|| || || (load "swclib")<br />
|-<br />
| ABC ||n.a.||List of strings comprising the alphabet, uppercase|| || || (load "swclib")<br />
|-<br />
| numstr||n.a.||List of strings from 1 to 9, rather than numbers|| || || (load "swclib")<br />
|-<br />
| aurebesh-caps ||n.a.||List of strings comprising the Aurebesh alphabet, with the initial letter capitalised|| ||"Aurek" "Besh" ... || (load "swclib")<br />
|-<br />
| aurebesh-lc ||n.a.||List of strings comprising the Aurebesh alphabet, all lowercase|| || "aurek" "besh" ... || (load "swclib")<br />
|-<br />
|}<br />
<br />
<br />
==Lists==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| join||separator-character list||Combines the elements of ''list'' with the ''separator-character'' to form a string||(join ", " (list "Green" "Blue" "Yellow")) ||"Green, Blue, Yellow, " || (load "funlib")<br />
|-<br />
| map||function list||Calls ''function'' for each member of ''list'' and returns the list of results||(map (lambda (x) (+ x 2)) (list 1 0 4)) ||(3 2 6)|| (load "funlib")<br />
|-<br />
| apply-foreach||function list||Calls ''function'' once for each member in ''list'', using the element as the single parameter. Returns #f (i.e., does not return a list of results)||(apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) ||I like<br />cheesy poofs.<br />Do you? || (load "funlib")<br />
|-<br />
| append||list element||Adds ''element'' to the end of ''list'' ||(append (list 1 2) 3) ||(1 2 3) || (load "funlib")<br />
|-<br />
| list-append||list1 list-to-append||Adds all the elements of the list ''list-to-append'' to the end of ''list1'' ||(list-append '(1 2) '(3 4)) ||'(1 2 3 4) || (load "funlib")<br />
|-<br />
| reduce||function init list||Reduces a list to a single value, using the combiner ''function'' provided, which function takes two inputs ''init'' and ''(car list)'' ||(reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) ||12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] || (load "funlib")<br />
|-<br />
| repeat-fn||function num-times object||Repeats ''function'' for the number of ''num-times'' on ''object'' ||(repeat-fn (lambda (x) (+ x 1)) 4 0)||4|| (load "funlib")<br />
|-<br />
| rand-from-list-unique||n list||Returns a list of ''n'' elements taken randomly from ''list'', without any duplicates, even if an element appears multiple times in ''list''. ''n'' is an integer and ''list'' is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP ||(rand-from-list-unique 7 '(a b c d a a q)) ||'("c" "d" "a" "b" "q")|| (load "funlib")<br />
|-<br />
| find-first-of||vals list-to-search (matchfun? eq?)||Returns a list of the first value in ''vals'' found in ''list-to-search'' and the first position (integer with 0 = first element) in list-to-search where vals is found. ''vals'' is an atom or a list of atoms to look for in list-to-search||(find-first-of (list 0 2 5) (list 1 3 2 7 5 0))||(list 2 2)|| (load "funlib")<br />
|-<br />
| find-in||atom list-to-search (start-position -1) (matchfun? eq?)||Returns the first position (integer with 0 = first element) where ''atom'' is found in ''list-to-search''||(find-in 7 (list 3 6 1 7 3 9 7))||3|| (load "funlib")<br />
|-<br />
| zip||list1 list2||Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length||(zip '(1 2 3 4) '(a b c d))||'((1 a) (2 b) (3 c) (4 d))|| (load "funlib")<br />
|-<br />
| without||needle haystack ||Returns a list equal to ''haystack'' with all occurrences of ''needle'' removed. ''haystack'' is a list of atoms and ''needle'' is an atom||(without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) ||(list "red" "yellow" "orange" "white")|| (load "funlib")<br />
|-<br />
| l-to-csv||my-list ||Returns a csv-concatenated list of the elements of ''my-list''. ''my-list'' is a list of atoms which are convertible to strings ||(l-to-csv '(1 b a 3 d c)) ||'("1,b,a,3,d,c")|| (load "funlib")<br />
|-<br />
| replace-nth||my-list n value||Returns a list which is a copy of ''my-list'' with the nth value changed. ''my-list'' is a list, ''n'' is an integer, ''value'' is a s-expression. Note: the first element of a list is 0. ||(replace-nth '(a b c d e f g) 3 "Hornswaggle") ||'( a b c "Hornswaggle" e f g) || (load "funlib")<br />
|-<br />
| matchup||val searchlist fetchlist ||Finds the position of the first occurrence of ''val'' in ''searchlist'', and returns the same position element of ''fetchlist''. ''val'' is a value to search for, ''searchlist'' is a list to search in, and ''fetchlist'' is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of ''fetchlist'' is a symbol ||(matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) ||"An eagle"|| (load "funlib")<br />
|-<br />
| remove-first||needle haystack ||Returns ''haystack'' without the first occurrence of ''needle'' located in it. ''needle'' is an atom, ''haystack'' is a list ||(remove-first x '(1 2 4 x f x 4)) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| remove-nth-of||haystack nth ||Returns ''haystack'' without the ''nth'' element. ''haystack'' is a list, ''nth'' is an integer. Note: the first element of a list is the 0th element ||(remove-nth-of '(1 2 4 x f x 4) 3) ||'(1 2 4 f x 4)|| (load "funlib")<br />
|-<br />
| ziplets||list-of-lists ||Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. ''list-of-lists'' is a list of lists of atoms ||(ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) ||(("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) || (load "funlib")<br />
|-<br />
| sublist-firstof||list-of-lists ||Returns a list of the <code>car</code> of each sublist || || || (load "funlib")<br />
|-<br />
|}<br />
<br />
==Conditional Statements==<br />
{| class="wikitable sortable" border="1" cellspacing="0" cellpadding="5" align="center"<br />
! Function Name <br />
! Required &Optional ("&") Parameters<br />
! Description<br />
! Example Text<br />
! Example Evaluation<br />
! Notes<br />
|-<br />
| case||val caselist &compfun||''val'' is the value to check against; each case in ''caselist'' which is a list of <code>case</code> lists in the form `(checkval ,toDo); ''&compfun'' is an optional function which takes 2 parameters and outputs #t or #f. Default is <code>eq?</code>. Note: <code>eq?</code> doesn't work on lists, so only use atoms for the checkval. It is also possible to write a <code>case</code> type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) ||`(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) || || (load "funlib")<br />
|-<br />
| cond|| [test result] ||''test'' is a s-expression that evaluates to #t or #f, ''result'' is a s-expression to execute if true ||(cond<br />[is-owner? (say "Hi, Boss!")]<br />[#t (say "Hello World!")]) || ||<br />
|-<br />
|}<br />
<br />
*[[Scripting]]<br />
*[[SWC LISP/Debugging and Errors]]<br />
*[[SWC LISP/Admin-Only Functions]]<br />
*[[SWC LISP/Modules]]<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP/Modules&diff=3744SWC LISP/Modules2018-09-14T16:47:05Z<p>Ruben Wan: /* Public Script Modules */</p>
<hr />
<div>==Public Script Modules==<br />
See the Rules Page on SWC for additional explanation.<br />
<br />
===swclib===<br />
(load "swclib")<br />
<br />
Contact: Selatos; Kay Dallben<br />
<br />
===funlib===<br />
(load "funlib")<br />
<br />
Contact: Selatos, Kay Dallben<br />
<br />
===mathematics===<br />
(load "mathematics")<br />
<br />
Contact: Kay Dallben<br />
<br />
<br />
===timelib===<br />
(load "timelib")<br />
<br />
Contact: Kay Dallben, mackaybre at gmail dot com<br />
<br />
===KayD-StringShortcuts===<br />
This library was removed as module and cannot be loaded. However, it is possible to use the functions by copying/pasting them.<br />
These functions insert appropriate pronoun string based on gender.<br />
<br />
(defun (female? (who self))<br />
(cond<br />
[(eq? (get-gender who) "female") #t]<br />
[#t #f]))<br />
<br />
(defun (male? (who self))<br />
(cond<br />
[(eq? (get-gender who) "male") #t]<br />
[#t #f]))<br />
<br />
(defun (HeShe? (who self))<br />
(cond<br />
[(female? who) "She"]<br />
[#t "He"]))<br />
<br />
(defun (heshe? (who self))<br />
(cond<br />
[(female? who) "she"]<br />
[#t "he"]))<br />
<br />
(defun (HerHis? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "His"]))<br />
<br />
(defun (herhis? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "his"]))<br />
<br />
(defun (HerHim? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "Him"]))<br />
<br />
(defun (herhim? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "him"]))<br />
<br />
Examples:<br />
* (say (concat "Yes, " (heshe (get-npc 54486)) " is pretty silly.")) -> "Yes, he is pretty silly."<br />
* (describe (concat (HerHis self) " gun points directly at you.")) -> Her gun points directly at you.<br />
* <b>heshe</b> <i>player-NPC-object</i><br />
* <b>HeShe</b> <i>player-NPC-object</i><br />
* <b>herhis</b> <i>player-NPC-object</i><br />
* <b>HerHis</b> <i>player-NPC-object</i><br />
* <b>herhim</b> <i>player-NPC-object</i><br />
* <b>HerHim</b> <i>player-NPC-object</i><br />
<br />
==Keyboard-Al Sayif==<br />
This Script Module (and paired NPC-Script requirements) enables a character-by-character input of a string into a script.<br />
<br />
NPC Script Requirements<br /><br />
;;;; ---------------------------------------------<br />
;; Corresponding Content for NPC/Entity<br />
<br />
(load "Keyboard-Al Sayif" "")<br />
(load "swclib")<br />
<br />
(bind-keyboard-mself (get-id self) 'npc)<br />
(bind-keyboard-convo say say-c describe describe-c ooc ooc-c)<br />
(bind-keyboard-responses add-action add-response add-text)<br />
(bind-keyboard-utils clear-window)<br />
<br />
(defun oncancel<br />
; Called when you hit the Cancel Button. Edit as needed.<br />
(ooc "Cancelled Keyboard Input."))<br />
<br />
(defun onfinish<br />
; called when user clicks the Enter button. Edit as needed.<br />
(clear-window)<br />
(say (myconcat "Well it's very nice to meet you, Mr. " (get-keyboard-response))))<br />
<br />
(bind-keyboard-callbacks onfinish oncancel)<br />
<br />
(defun start ;; Example to go straight into it. Edit as needed, or just use start-keyboard.<br />
(describe "Enter your input on the keypad. As you click the screen will update.")<br />
(start-keyboard))<br />
<br />
;;;; ---------------------------------------------<br />
<br />
===start-keyboard===<br />
* clears the window and starts the Keyboard Input script: Asks for input character by character. CAPS toggles between UPPERCASE and lowercase for letter, BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
===get-keyboard-response===<br />
* returns a string of the saved input from the keyboard.<br />
<br />
COMING SOON<sup>TM</sup><br />
<br />
===start-keypad===<br />
* clears the window and starts the Keypad Input script: Asks for input character by character (numbers 0 - 9 only). BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
Contact: Kay Dallben<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wanhttp://guide.swcombine.com/index.php?title=SWC_LISP/Modules&diff=3743SWC LISP/Modules2018-09-14T16:45:15Z<p>Ruben Wan: /* Public Script Modules */</p>
<hr />
<div>==Public Script Modules==<br />
See the Rules Page on SWC for additional explanation.<br />
<br />
===swclib===<br />
(load "swclib")<br />
<br />
Contact: Selatos; Kay Dallben<br />
<br />
===funlib===<br />
(load "funlib")<br />
<br />
Contact: Selatos, Kay Dallben<br />
<br />
===mathematics===<br />
(load "mathematics")<br />
<br />
Contact: Kay Dallben<br />
<br />
===KayD-StringShortcuts===<br />
This library was removed as module and cannot be loaded. However, it is possible to use the functions by copying/pasting them.<br />
These functions insert appropriate pronoun string based on gender.<br />
<br />
(defun (female? (who self))<br />
(cond<br />
[(eq? (get-gender who) "female") #t]<br />
[#t #f]))<br />
<br />
(defun (male? (who self))<br />
(cond<br />
[(eq? (get-gender who) "male") #t]<br />
[#t #f]))<br />
<br />
(defun (HeShe? (who self))<br />
(cond<br />
[(female? who) "She"]<br />
[#t "He"]))<br />
<br />
(defun (heshe? (who self))<br />
(cond<br />
[(female? who) "she"]<br />
[#t "he"]))<br />
<br />
(defun (HerHis? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "His"]))<br />
<br />
(defun (herhis? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "his"]))<br />
<br />
(defun (HerHim? (who self))<br />
(cond<br />
[(female? who) "Her"]<br />
[#t "Him"]))<br />
<br />
(defun (herhim? (who self))<br />
(cond<br />
[(female? who) "her"]<br />
[#t "him"]))<br />
<br />
Examples:<br />
* (say (concat "Yes, " (heshe (get-npc 54486)) " is pretty silly.")) -> "Yes, he is pretty silly."<br />
* (describe (concat (HerHis self) " gun points directly at you.")) -> Her gun points directly at you.<br />
* <b>heshe</b> <i>player-NPC-object</i><br />
* <b>HeShe</b> <i>player-NPC-object</i><br />
* <b>herhis</b> <i>player-NPC-object</i><br />
* <b>HerHis</b> <i>player-NPC-object</i><br />
* <b>herhim</b> <i>player-NPC-object</i><br />
* <b>HerHim</b> <i>player-NPC-object</i><br />
<br />
==Keyboard-Al Sayif==<br />
This Script Module (and paired NPC-Script requirements) enables a character-by-character input of a string into a script.<br />
<br />
NPC Script Requirements<br /><br />
;;;; ---------------------------------------------<br />
;; Corresponding Content for NPC/Entity<br />
<br />
(load "Keyboard-Al Sayif" "")<br />
(load "swclib")<br />
<br />
(bind-keyboard-mself (get-id self) 'npc)<br />
(bind-keyboard-convo say say-c describe describe-c ooc ooc-c)<br />
(bind-keyboard-responses add-action add-response add-text)<br />
(bind-keyboard-utils clear-window)<br />
<br />
(defun oncancel<br />
; Called when you hit the Cancel Button. Edit as needed.<br />
(ooc "Cancelled Keyboard Input."))<br />
<br />
(defun onfinish<br />
; called when user clicks the Enter button. Edit as needed.<br />
(clear-window)<br />
(say (myconcat "Well it's very nice to meet you, Mr. " (get-keyboard-response))))<br />
<br />
(bind-keyboard-callbacks onfinish oncancel)<br />
<br />
(defun start ;; Example to go straight into it. Edit as needed, or just use start-keyboard.<br />
(describe "Enter your input on the keypad. As you click the screen will update.")<br />
(start-keyboard))<br />
<br />
;;;; ---------------------------------------------<br />
<br />
===start-keyboard===<br />
* clears the window and starts the Keyboard Input script: Asks for input character by character. CAPS toggles between UPPERCASE and lowercase for letter, BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
===get-keyboard-response===<br />
* returns a string of the saved input from the keyboard.<br />
<br />
COMING SOON<sup>TM</sup><br />
<br />
===start-keypad===<br />
* clears the window and starts the Keypad Input script: Asks for input character by character (numbers 0 - 9 only). BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`<br />
<br />
Contact: Kay Dallben<br />
<br />
<br />
[[Category:SWC LISP]]</div>Ruben Wan