PDA

View Full Version : Giving Link a Triforce Piece?



Joe123
04-02-2008, 08:16 AM
Game->LItems[6] & LI_TRIFORCE = 1;

Why can't I do this?
Shouldn't that give Link Level 6's Triforce Piece?

It doesn't compile.

C-Dawg
04-02-2008, 03:42 PM
I don't follow.

Link->Item[6] = true;

Thats what you're trying to do, right?

Joe123
04-02-2008, 06:13 PM
¬_¬

Yeah, that won't do anything at all.

ScaryBinary
04-06-2008, 01:05 PM
You almost had it Joe123...right idea, but your syntax wasn't quite right. I tested this snippet out and it worked.

import "std.zh"

ffc script GiveTriforce{
void run(int Level){
Game->LItems[Level] = Game->LItems[Level] | LI_TRIFORCE;
}

}

I attached this to an FFC on the screen; set the first argument to the level number of the triforce you want to give link.

The Bitwise OR raises its ugly head! Each element in the LItems array is basically just a number. What we're doing here is setting individual bits in the number. The lowest bit indicates whether or not Link has the level's Triforce piece. The next bit indicates whether or not Link has the level's map (..and so forth, look at std.zh). So for instance, if Link has only Level 2's Triforce piece, LItems[2] will equal "1". If Link has only Level 2's map, LITems[2] will equal "2". If Link has Level 2's Triforce piece and map, then LItems[2] will equal "3" ---- LI_TRIFORCE (which is "1") plus LI_MAP (which is "2").

To set one of these items, use the method in the snippet above - the Bitwise OR. To check if Link has one of the items, use the Bitwise AND as follows:

if ((Game->LItems[2] & LI_TRIFORCE) == LI_TRIFORCE) {
// whatever...
}
To remove an item (I haven't tried this yet, it might be interesting), you'd Bitwise AND the item with "0" to clear it (because anything ANDed with 0 will be 0). I'll have to remember back to my coding days for the trick to do this. It's something like:

Game->LItems[2] == Game->LItems[2] & ~LI_TRIFORCE;
...but don't take my word on it....!

Of course, check out the Wiki (http://www.shardstorm.com/ZCwiki/Bitwise_operators) for some Bitwise operator stuff.

Joe123
04-06-2008, 01:11 PM
Ah thanks =)
I do understand how it works, I just wasn't thinking properly.

I've done checks for the compass and things before.


What's the tilde for?

ScaryBinary
04-06-2008, 02:27 PM
Ah, that's right, the walkability flags also use the bitwise stuff.

The tilde...I think it's the bitwise NOT...but I don't remember for sure. Given a number, it would change all the 0s to 1s and all the 1s to 0s.

For example, LI_MAP has a decimal value of 2, which would be 00000010 in binary. So if LI_MAP is 00000010, then ~LI_MAP would be 11111101.

Let's assume that Link has both the map and the triforce for Level 2. This means that LItems[2] is 3, which is 00000011 in binary. Now if we want to take away the map, we would write:

Game->LItems[2] = Game->LItems[2] & ~LI_MAP;
We just noted that ~LI_MAP would be 11111101, and we also know that LItems[2] is 00000011. Substituting these into the expression on the right gives us:

Game->LItems[2] = 00000011 & 11111101;
Since anything ANDed with 0 is 0, the above expression takes away the map, and also ensures that we don't accidentally give Link something else. We end up with a value of 00000001 - so Link keeps the Triforce piece, but he loses the map.

I haven't actually tried this yet, so I'm still not sure if "~" is actually the Bitwise NOT, nor am I sure if the scripting engine will actually let you remove items like this. I'll give it a shot as soon as I post this.....

*EDIT* Looks like the tilde is the Bitwise NOT. I was able to remove a Triforce piece from Link using the approach outlined above. Cool.:D

Joe123
04-06-2008, 06:24 PM
Ah thanks, that's great ^_^

Now I just need it to work for level 10 =P

That's going to be a different matter entirely ^_^


We'll see how it goes.