lua:scriptenvironments
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| lua:scriptenvironments [2015/10/17 20:51] – [Finding the correct environment] aethyn | lua:scriptenvironments [2016/02/08 04:45] (current) – [Script Environments] vodur | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Script Environments ====== | ====== Script Environments ====== | ||
| - | With the exception of the [[: | + | All prog scripts run in the scripting |
| + | |||
| + | There are a few ways to share values between different script | ||
| ===== Simple interactions ===== | ===== Simple interactions ===== | ||
| Line 62: | Line 64: | ||
| There are many [[: | There are many [[: | ||
| - | ==== getmobworld() ==== | + | ==== getmobworld() and getobjworld() ==== |
| + | |||
| + | These two functions work the same way. Only getmobworld() is shown, but the examples can be made to fit getobjworld(), | ||
| <code lua> | <code lua> | ||
| Line 81: | Line 85: | ||
| In this example we've looped over the getmobworld() list for that vnum, but also "broke out" in a more conventional way. A mob has a ROOM property, which has a vnum property. In that way we can find out which room a mobile is in and make them sleep if they' | In this example we've looped over the getmobworld() list for that vnum, but also "broke out" in a more conventional way. A mob has a ROOM property, which has a vnum property. In that way we can find out which room a mobile is in and make them sleep if they' | ||
| + | |||
| + | ==== getpc() and getroom() ==== | ||
| + | |||
| + | getpc() takes a string argument. It, like getroom(), can return only one object because PC names are unique. | ||
| + | |||
| + | <code lua> | ||
| + | -- TIMER. Every 5 minutes let's give Vodur a hug. He deserves it. | ||
| + | if getpc(" | ||
| + | mob: | ||
| + | mob: | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | This contrived example is obviously not very useful. In the Cards Against Humanity script we can see how to use getpc() in a more constructive way: | ||
| + | |||
| + | <code lua> | ||
| + | function check_player_num() | ||
| + | for _,v in ipairs(players) do | ||
| + | if not(getpc(v.name)) then | ||
| + | missing_players = {} | ||
| + | table.insert(missing_players, | ||
| + | active_players = #players - # | ||
| + | end | ||
| + | end | ||
| + | if active_players> | ||
| + | start_hand() | ||
| + | else | ||
| + | for _,j in ipairs(players) do | ||
| + | tell(j.name, | ||
| + | tell(j.name, | ||
| + | delay(30, final_check) | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | In the function the " | ||
| + | |||
| + | getroom() is even more straightforward. Since ROOMs of a certain vnum always exist, using getroom() will always allow you to access that ROOMs properties and methods. For instance, we can turn a " | ||
| + | |||
| + | <code lua> | ||
| + | -- DEATH. Make the exit up from 22000 visible. | ||
| + | getroom(22000).up: | ||
| + | </ | ||
| + | |||
| + | Again, there' | ||
lua/scriptenvironments.1445115100.txt.gz · Last modified: 2015/10/17 20:51 by aethyn