Suppose each item sprite's "auto" script generates a unique piece of text for that particular sprite? A piece of text that's guaranteed to be different from all other sprites, but will always be the same every time that particular sprite generates it?
Well... each sprite has a different name.
And you can access it by writing
[this._name] like so:
Well, that's fine, but what about the
other levels?
There might be a sprite with this name in another level.
Well, if you think about it, each level has a unique name too.
Okay, but how can a sprite access that??
Well, by typing
[LEVEL.levelData.name] like so:
And if you combined these two pieces of text together, you'd get something like this:
levels\pallet\pallet_town.lvlitem_ballDon't worry about what it means. It's just a jumble of letters, but what's important is that it's a
unique jumble of letters that
only this particular sprite, in this particular level would see when it looks at [LEVEL.levelData.name] and [this._name]
Now suppose you created a variable named... that.
Yes, I actually mean doing something like this:
- Code: Select All Code
levels\pallet\pallet_town.lvlitem_ball = true
We're going to create a variable whose name is "levels\pallet\pallet_townlvlitem_ball"
This is actually possible. You can theoretically create variables with completely crazy characters in them. Even spaces!
(I don't normally recommend it) But there is
one thing you cannot put into a variable's name... periods.
(the level's file-path ends with .lvl)So now we have to remove all periods from the text.
We can do that by using a helper function I built into the game.
The helper function is
RAM_F.removeText(By the way, if you try to use a textbox to display this text to see what it looks like, it won't display right because textboxes use \ for dialog commands like pauses and it'll look like letters are missing. Don't worry, they are still there even if the textbox refuses to show them)Now granted, after doing this it would be a pain to have to actually
type this text in. But we can generate this text and store it in a variable and then just use that variable.
This is where things get mind-bending.
We're going to use a variable to store the name... of another variable.
A name is just text after all.
And THAT... is how you can make a variable named
levels\pallet\pallet_town.lvlitem_ball and store the value
true inside of it.
[this.variableName] also works in
IF commands.
If we can create different variables for each item sprite, we can use IF commands to detect when those variables are already true and remove the sprite.
So instead of using appearance flags, I have an "auto" script that detects a variable and immediately removes the item if that variable is true. Why is this useful? Because it's possible to generate a unique variable-name based on the level path and the item sprite's name.
If you kept the
_common.lvl level file in your pokemon game, you should see a sprite named "item_ball" in there which optionally uses this trick.
(It also does a bunch of other things)