1. What is MyScript?
Often when designing a custom element, scripted behavior, or even just in trying to check a challenge, one finds oneself wishing they could point to a location or rectangle of locations relative to some object whose own location may change during gameplay. The normal behavior of a Build or Generate Entity command, for example, or the Wait for Entity/Item At commands, only allow one to specify a single static tile or group of tiles, and do not allow for this kind of dynamic selection of a location. Fortunately, there
is still a way to do it. This is exactly what the _MyScript variables are for! And they can do even more than this, generating or building or checking for some undocumented or dynamically-selected items or entities, just for starters. But _MyScripting is a slightly arcane art in DROD scripting, requiring a great deal of care not to make your element break within a couple of turns, or crash the game, or other horrible things.
2. How do I use MyScript?
The basic format of a code involving MyScript injection is as follows:
Set var "_MyScript*" = 0
(Whatever command uses the _Myscript override)
Set var "_MyScript*" = -9999
Here "
*"
can be X, Y, W, H, or F. For location-based commands, X and Y specify the X and Y locations for the command to point at. If you want to specify a rectangle, X and Y give the script the
upper left corner of the rectangle, W tells the script how for to the
east the desired rectangle goes (with W = 0 indicating "
just the one tile"
, W = 1 indicating "
the tile and the one to the east of it"
, and so on), and H similarly says how far to the
south. For commands
not based on location, or not entirely based on location, X, Y, W, and H can mean various other things; F is also used to mean various other things besides location just in general.
As an example, if I wanted a character to check the 3x3 square with itself at the
center for the presence of a Roach, the code would look like this:
Click here to view the secret text
× Set var "_MyScriptX" = _MyX-1
Set var "_MyScriptY" = _MyY-1
Set var "_MyScriptW" = 2
Set var "_MyScriptH" = 2
If ...
Wait for entity type Roach,0,0,0,0
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
Set var "_MyScriptW" = -9999
Set var "_MyScriptH" = -9999
(Whatever other commands you wanted to execute)
If End
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
Set var "_MyScriptW" = -9999
Set var "_MyScriptH" = -9999
Notice that I set _MyScriptX and _MyScriptY to the
upper left corner of the 3x3 square by moving 1 to the north and 1 to the west of the character's current position (which is always _MyX, _MyY), and then set H and W both to 2 to specify that you want a 3x3 rectangle (err, square). It is helpful while doing any kind of location-based commands to remember that
North and West are subtraction, South and East are addition.
You may wonder why I'm setting all of the relevant variables to -9999 at the end. This is because for any MyScript variable, the value -9999 translates as "
do not override"
. MyScript variables affect all kinds of commands, such as the Wait command, and failing to set them back to -9999 as soon as you're done with them will frequently result in unintended behavior. So remember to
always, ALWAYS reset your MyScripts to -9999. If there's something buggy going on with your scripted character and you don't know why, this should be the
first thing you check for before coming to anyone else for help, because even among experienced script-writers it's the most probable cause for something to go wrong.
3. MyScript and Orientations
When you set or check the orientation of an entity (that is, which way it's facing) by messing with _O or _MyO, or using a command such as Get Entity Direction, it's helpful to know what number means what direction. That correspondence is as follows, where X is the entity's location:
A good way to remember this is to just write down the numbers from 0 to 8 in a left-to-right, top-to-bottom order arranged into 3 rows of 3 numbers each. What about 4, which is in the center? 4 is treated as "
no direction"
and usually doesn't mean anything and crashes stuff. It's mainly there as a placeholder so that the math works out for all of the other numbers.
One reason that orientations are numbered in this way (or at least, a good justification for it) comes in the form of a few handy tricks you can do with this. For example, when you want to reverse the orientation of an entity, you don't have to go through detecting which of the 8 orientations it has to figure out what the opposite is. You can just take _MyO = 8 - _MyO. Check it with the chart above if you don't believe me! Better still, if you want a character to just move in the direction it's facing, there is a very simple way to do this as well, using _MyScript:
Set var "_MyScriptX" = (_MyO % 3) - 1
Set var "_MyScriptY" = (_MyO / 3) - 1
Move 0,0,0,0
Simple! And it all works because of the math involved in X, Y, and O variables. A slight modification of this will allow you to teleport an entity to the location 1 tile in the direction of its orientation instead, in case you don't want a turn-stopping command quite so soon:
Set var "_MyScriptX" = _MyX + (_MyO % 3) - 1
Set var "_MyScriptY" = _MyY + (_MyO / 3) - 1
Teleport to 0,0
As a final note, any command involving orientations may also take 9 to mean "
rotate CW"
and 10 to mean "
rotate CCW"
where those statements make sense.
4. The Promised Reference
What follows is a list of everything I could dig up about how various commands are affected by the different _MyScript* variables. Some of this is taken from other pre-existing threads, some of it from my own testing or memory, but at any rate it should be helpful for anyone hoping to make use of this powerful tool.
A list of commands for which X and Y specify the X, Y location for the command to be applied to:
Click here to view the secret text
×Activate Item at
Ambient sound at
Appear at
Attack Tile
Game Effect
Generate Entity
Get entity direction
Move to
Teleport Player to
Teleport to
A list of commands for which X, Y, W, and H specify the rectangle in which the command is applied:
Click here to view the secret text
×Build
Build marker
Destroy Trapdoor
Wait for entity
Wait for entity type
Wait for item
Wait while entity
Wait while entity type
A list of commands whose only parameter is changed by setting X
Click here to view the secret text
×Cut scene
Display Filter (0 1 2 3 = the four options in order probably)
Face Direction (X = orientation number, as above)
Flush Speech (not sure of effect)
Wait
Wait for open move (X = orientation number)
Wait for player to face/input/move (X = orientation number (EXCEPT FOR NORTHWEST, WHICH IS 11 (but only for input?)); input also takes some more values for Wait and Special Command)
Wait for turn
Generate Entity takes this value of _MyScriptH to mean this entity; "Wait for/while entity type" takes the same values of _MyScriptF to mean the same entity (based on this thread):
Click here to view the secret text
×0: Roach
1: Roach queen
2: Roach egg
3: Goblin
4: Nothing. Formerly neather?
5: Wraithwing
6: Evil Eye
7: Red Serpent (can't generate entity)
8: Tar mother
9: Tarspawn
10: Brain
11: Mimic
12: Spider
13: Adder (can't generate entity)
14: Rattlesnake (can't generate entity)
15: Golem
16: Waterskipper
17: Waterskipper Nest
18: Aumtlich
19: Clone
20: Decoy
21: Wubba
22: Seep
23: Stalwart
24: Young Halph
25: 39th
26: Fegundo
27: Fegundo ashes (can't generate entity)
28: Guard
29: Character (probably can't generate)
30: Mud mother
31: Mud baby
32: Gel mother
33: Gel baby
34: Citizen
35: Rock giant
36: Halph
37: Slayer
38: Soldier
39: Engineer
40: Construct
41: Gentryii (including chain); can't generate entity
42: Temporal projection
43: Fluff
Build/Build Marker/Wait for Item at take this value of _MyScriptF to mean this item type (based on this thread):
Click here to view the secret text
×0:
1: Floor
2: Pit
3: Stairs
4: Wall
5: Broken wall
6: Blue door
7: Green door
8: Red door
9: Yellow door
10: Yellow open door
11: Trapdoor
21: Invisibility Potion
22: Mimic Potion
23: Scroll
24: Orb
35: Tar
36: Checkpoint
37: Black Door
38: Speed Potion
39: Briar root
40: Withered briar
41: Briar growth
43: Bomb
44: Fuse
47: Tunnel north
48: Tunnel south
49: Mirror
50: Clone
51: Decoy
52: Water platform (can't really build; don't try)
53: Platform (can't really build; don't try)
54: Floor mosaic
55: Road
56: Grass
57: Dirt
58: Alternate floor
59: Master wall (you can't actually build this)
60: Mud
61: Stairs up
62: Secret wall
63: Tunnel east
64: Tunnel west
65: Image floor
66: Hard wall
67: Water
68: Open green door
69: Open blue door
70: Open red door
71: Open black door
72: Trapdoor over water
73: Oremites
74: Light
75: Hot tile
76: Gel
77: Relay station
78: Multiuse pressure plate
79: Bridge
80: Horizontal bridge
81: Vertical bridge
82: Image pit
83: Image wall
86: Shallow water
87: Squad horn
88: Soldier horn
89: Stepping stone
90: Seeding beacon
91: Seeding beacon off
92: Powder keg
93: Floor spikes
103: Fluff
104: Fluff vent
105: Thin ice
106: Thin ice over shallows
107: Fire trap
108: Active fire trap
109: Hold complete wall (you can't build this)
157: Start of unregistered stuff?
Negative values are used for tokens:
-4: Rotate CW
-5: Rotate CCW
-6: Switch tar/mud
-7: Switch tar/gel
-8: Switch mud/gel
-9: Vision
-10: Power
-11: Disarm
-12: Persistence
-13: Conquer
-14: Sword
-15: Pickaxe
-16: Spear
-17: Staff
-18: Dagger
-19: Caber
-20: Temporal
The meaning of the value _MyScriptF in the Wait for Entity command:
Click here to view the secret text
×1: Player
2: Halph
4: Monster
8: NPC
16: Double
32: Self
64: Slayer
128: Beethro
256: Stalwart
Adding two or more of these numbers together checks for entities corresponding to all numbers going into the sum.. So, for example, 7 = 1 + 2 + 4 means "check for Player, Halph, or Monster".
Other Notes:
-_MyScriptW determines the orientation of the generated entity for Generate Entity.
-_MyScriptF changes the attack type of Attack Tile.
-Generate Entity takes _MyScriptW as the orientation of the newly-generated entity
-Game Effect's Direction, Sound Effect option, and which effect it is can be specified by W, H, and F in some order, but I don't know which one.
-Flashing Message can have its color altered by X.
-Face towards like guard and Move to probably have which entity type the facing or moving toward is aimed at by _MyScriptX, with the Forbid turning and Single step options affected by some others among Y, W, H, and F.
-In DROD RPG, Speech Custom (which is also displayed as "
Speech at"
) can have its location dynamically determined the same way as Attack Tile, etc., but my testing indicates this does not work in normal DROD. It's possible I'm just doing it wrong, however.
-When setting the relative positions of things,
be wary of going outside room bounds! This means look out for any X or Y values less than 0, an X value bigger than 37, a Y value bigger than 31, or a W or H value that will push the rectangle beyond the edge of the room. If you crash DROD trying to check for or build something, this may be a culprit.
-The two previous references on MyScript stuff can be found
here and
there, but the one that's there is for
DROD RPG and will not be completely accurate to what happens in regular DROD.
____________________________
109th Skywatcher
Here are some links to Things!
Click here to view the secret text
[Last edited by Xindaris at 07-13-2024 04:47 AM]