first off: never, ever,
ever use
pairs() in an Aleph One script. it’s horrifically broken and will fuck up network games, film playback, and probably more (its biggest problem being that there’s no guarantee it will ever sort its data the same way on two machines or twice in a row, which to my understanding is because it depends on the ordering of data in memory, and there’s absolutely nothing deterministic about that. it is a horrible, horrible, cursed iterator that probably shouldn’t even exist. it is used for indexing tables that have non-numeric keys, or keys that start with values lower than 1, or non-consecutive keys, but... that’s also cursed. if it were up to me, aleph one would print a warning every time someone used pairs()).
ipairs() at least won’t do the former two (because it actually is deterministic), so if you have to use either of them, use that. and if for some cursed reason you need an iterator function that doesn’t iterate over consecutive integers, write your own rather than ever using
pairs().
secondly, there’s no need to iterate through all sides for every line;
Lines[x].cw_side and
Lines[x].ccw_side will get you the only possible sides the line could have.
third,
Player:print won’t work; you want
Players.print
fourth, there’s no need to write
TransferModes["landscape"]; you can just write
"landscape" (with the quotes).
fifth, never, ever tie any script that’s meant for more than onetime use to specific index numbers, because those will change whenever you delete lines/sides/polygons/points with smaller indices. that’s a good way to doom yourself to having to rewrite your script over and over, and ain’t nobody got time for that. for what you’re trying to do, it’s better to set a specific texture that will be replaced globally throughout the map, iterate through all sides, and change anything that uses that texture. however, if your map is sufficiently large, that could cause noticeable lag, so i’d recommend doing it over a second or so. one easy way to do this is to set an iterator, which i’ll label as
i, to 0 when you start running this part of the script. (before this point, you’d want to set it as nil, or simply not bother defining it.) define this function:
Code: Select all
function retexture(x)
if x.texture_index == FROM_TEXTURE and x.collection == FROM_COLLECTION then
x.texture_index = TO_TEXTURE
x.collection = TO_COLLECTION
x.transfer_mode = "landscape"
end
end
then run this somewhere in Triggers.idle():
Code: Select all
if i and i < 30 then
for s in Sides() do
if s.index % 30 == i then
retexture(s.primary)
retexture(s.secondary)
retexture(s.transparent)
end
end
i = i + 1
end
(the
i and part of
if i and i < 30 is necessary to prevent the game from printing a warning about comparing nil with a number. this should not be necessary with the == operator, since that means “if (variable) exists and is equal to (number)”, but < and > aren’t so sophisticated.)
and obviously, you’ll want to define FROM_TEXTURE, FROM_COLLECTION, TO_TEXTURE, and TO_COLLECTION at the start of your script. convention is to write constants in all caps so that they stand out and can be easily changed to facilitate code reuse.
lastly, you’ll probably want to do something similar for polygon floors and ceilings, just for completeness’ sake.
i haven’t tested this because i don’t know for sure what you’re planning to use the script for, so let me know if there are any problems. i’ve written similar retexture scripts before that worked fine, though.
“People should not be afraid of their governments. Governments should be afraid of their people.” —V,
V for Vendetta (Alan Moore)
“The trouble is that we have a bad habit, encouraged by pedants and sophisticates, of considering happiness as something rather stupid. Only pain is intellectual, only evil interesting. This is the treason of the artist: a refusal to admit the banality of evil and the terrible boredom of pain. If you can’t lick ’em, join ’em. If it hurts, repeat it. But to praise despair is to condemn delight, to embrace violence is to lose hold of everything else. We have almost lost hold; we can no longer describe happy man, nor make any celebration of joy.” —Ursula K. Le Guin, “The Ones Who Walk Away from Omelas”
“If others had not been foolish, we should be so.” —William Blake,
The Marriage of Heaven and Hell
“The law cannot protect anyone unless it binds everyone; and it cannot bind anyone unless it protects everyone.” —Frank Wilhoit
Last.fm ·
Marathon Chronicles ·
Marathon Eternal 1.2 ·
Where Monsters Are in Dreams ·
YouTube Vidmaster’s Challenge