DocsMegalithObjects and the world
Forge objects by label
A script can find objects placed in Forge by a label saved with the map, so the same script works on any map whose objects carry it, with no positions or placement numbers in the source.
- Label the objectsIn Forge, as the host, aim at an object and open its Properties. Under Megalith scripting, enter a Label and a Spawn sequence, then choose Apply scripting.
- Save the mapThe values belong to the map: save it as for any edit.
- Find them in the scriptLoop over the label and tell the objects apart with
current_object.spawn_sequence. Host the mode on that saved map.
megalo-forge-labels.rmeg
-- In Forge, give two placed objects the label "door" and Spawn Sequences 1 and 2.
-- Save the map, then host this mode on that map.
-- The first door becomes invincible; the second is left alone.
alias door = global.object[0]
if door == no_object then
for each object with label "door" do
if current_object.spawn_sequence == 1 then
door = current_object
door.set_invincibility(true)
end
end
end
script_widget[0].set_visibility(all_players, true)
if door == no_object then
script_widget[0].set_text("Waiting for an object labelled door with Spawn Sequence 1")
end
if door != no_object then
script_widget[0].set_text("Door 1 found and protected")
end
The loop runs until it finds the door, then door keeps the reference.
- A label is a group name, not a unique name: several objects can share one, and capitals count. Up to 32 UTF-8 bytes without control characters; an empty label means none.
- Spawn sequence is a number from −128 to 127 that scripts read and can't change. It's separate from the Forge menu's Spawn Order, spare clips and teleporter channel. Objects without one, and objects the script creates, read 0.
- References last while the object does. When it's destroyed, a saved reference becomes
no_object. If the object respawns, find the new one with the loop again.aliasonly names a variable; it doesn't look an object up by label. - A missing label isn't an error. The game can't know which map you'll use, so a loop over a label no object has just visits nothing.
- Numbers match text.
with label 7finds objects labeled7. - Only the host edits labels, but players see them and can save them with the map. Move a frozen object before labeling it.
