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 05:16] – [Simple Interactions] 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 |
| - | ===== Simple | + | There are a few ways to share values between different script environments, |
| + | |||
| + | ===== Simple | ||
| The most common way to manipulate an outside environment is with the Prog Trigger mechanism. [[: | The most common way to manipulate an outside environment is with the Prog Trigger mechanism. [[: | ||
| Line 11: | Line 13: | ||
| <code lua> | <code lua> | ||
| -- GRALL. Let's say HI! to PCs | -- GRALL. Let's say HI! to PCs | ||
| - | if ch.ispc then – ispc is also a property of CH | + | if ch.ispc then -- ispc is also a property of CH |
| say(" | say(" | ||
| end | end | ||
| Line 29: | Line 31: | ||
| <code lua> | <code lua> | ||
| -- GRALL. Our PC entered this room | -- GRALL. Our PC entered this room | ||
| - | |||
| ch: | ch: | ||
| </ | </ | ||
| There is no qualitative difference between the two versions. | There is no qualitative difference between the two versions. | ||
| + | |||
| + | ===== Executing a single method in another environment ===== | ||
| + | |||
| + | In our above example damage() could be used in two different ways because the method belongs to CH. But what if you wanted an object to damage a player? OBJ does not have the method damage(), so you must "break out" into the CH environment. | ||
| + | |||
| + | In this example an object will hurt a player who tries to drop it: | ||
| + | |||
| + | <code lua> | ||
| + | -- DROP. Damage a player who tries to drop this object. | ||
| + | echo(" | ||
| + | ch1: | ||
| + | return false -- don't let them drop the object | ||
| + | </ | ||
| + | |||
| + | Since " | ||
| + | |||
| + | <code lua> | ||
| + | -- TIMER 5 seconds. Damage the player every 5 seconds. | ||
| + | if obj.carriedby then -- Make sure it's being carried | ||
| + | obj.carriedby: | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | In this case OBJs have a property " | ||
| + | |||
| + | ===== Finding the correct environment ===== | ||
| + | |||
| + | There are many [[: | ||
| + | |||
| + | ==== 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> | ||
| + | -- Let's find a mob with vnum 22000 and make him " | ||
| + | getmobworld(22000)[1]: | ||
| + | </ | ||
| + | |||
| + | Since we know there' | ||
| + | |||
| + | <code lua> | ||
| + | -- Make mob 22000 in room 22050 " | ||
| + | for _,mobile in ipairs(getmobworld(22000)) do | ||
| + | if mobile.room.vnum == 22050 then | ||
| + | mobile: | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | 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.1445059015.txt.gz · Last modified: 2015/10/17 05:16 by aethyn