PDA

View Full Version : float to bool



sps999
03-01-2009, 10:37 AM
I'm trying to make a fairy that when link's HP is zero, it'll make his hp full again. The thing is, whenever I try to make the script tell that link's health is zero, I can't do that without the game warning me that it is compiling from float to bool. I have tried to ways, the first one I am aware that is float -> bool, and the second one, I don't know why it thinks that.

BTW, the scripts compile fine.


import "std.zh"
item script fairy
{
void run()
{
if ( Link -> HP )0; // I know what I did wrong here.
{
Link -> HP = Link -> MaxHP;
}
}
}



import "std.zh"
item script fairy
{
void run()
{
if ( Link -> HP )Link -> HP = 0; // I don't know what I did wrong here.
{
Link -> HP = Link -> MaxHP;
}
}
}

Joe123
03-01-2009, 11:00 AM
They shouldn't compile.
If those scripts compile, you've broken something.

item script fairy{
void run(){
if (Link->HP == 0){ // This is what you meant. You were checking 'If Link->HP (is greater than 0)' rather than 'If Link->HP == 0'
Link -> HP = Link -> MaxHP;
}
}
}

That's what you meant, but I'm afraid it's not quite as simple as that.
When Link dies, the game ends.
Scripts don't have time to run, so you'd have to do something a little different if you wanted to make a fairy.

pkmnfrk
03-01-2009, 11:07 AM
Actually, the second script should compile. It just won't do what's expected:


import "std.zh"
item script fairy {
void run() {
if ( Link -> HP ) { //if Link's HP is greater than zero...
Link -> HP = 0; // ... set it to zero.
}
Link -> HP = Link -> MaxHP; //Then, set Link's HP to max.
}
}

Incidentally, we should have a slot 4 global script that triggers on Link's death. It would get to run for one frame, and if Link's HP is still zero after that, he dies for real.

sps999
03-01-2009, 11:10 AM
ok, thanks.


When Link dies, the game ends.


Would I be able to make something for the 3rd global script slot that check for the fairy item and fills up links health, or would link already be dead at that time?

Joe123
03-01-2009, 02:03 PM
The 3rd global script runs when the game is re-loaded rather than when Link dies, so no.

What you'd have to do is to give Link say 5 extra heart containers.
Hide them underneath something in the subscreen, and add an extra 5 to his starting health in init data.
Then have a bit of code in the global script which says 'if(Link->HP <= 5*16) Link->HP = 0;', and write the fairy code to say 'if(Link->HP <= 5*16) Link->HP = Link->MaxHP;'.


Actually, the second script should compile. It just won't do what's expected:


item script fairy
{
void run()
{
if ( Link -> HP )Link -> HP = 0; // I don't know what I did wrong here.
{
Link -> HP = Link -> MaxHP;
}
}
}

Surely this brace is a syntax error, because the if has already been 'used'; it ends when it sees the first semi-colon, and you can't just put braces wherever you like?

sps999
03-01-2009, 06:12 PM
What you'd have to do is to give Link say 5 extra heart containers.
Hide them underneath something in the subscreen, and add an extra 5 to his starting health in init data.
Then have a bit of code in the global script which says 'if(Link->HP <= 5*16) Link->HP = 0;', and write the fairy code to say 'if(Link->HP <= 5*16) Link->HP = Link->MaxHP;'.

I'll try it out, but I just have one worry.


'if(Link->HP <= 5*16) Link->HP = 0;

'if(Link->HP <= 5*16) Link->HP = Link->MaxHP;

Wouldn't they fight over the HP, or will Link just die? I don't know, but I'm gonna try it out.

pkmnfrk
03-01-2009, 06:13 PM
You can't? That's unusual. In C, and most languages based on it, you can put braces wherever you want.

Joe123
03-02-2009, 04:20 AM
Item scripts run before the global script.


And maybe you can and I just didn't realise.
Why would you need to?

sps999
03-02-2009, 10:58 AM
I've tried every variation of the global script I can think of, and they all do either 3 things. 1. Die instantly (because I seperated the if statement from the action.) 2. Doesn't Compile Right. 3. Not do anything at all, when I lose all my visible hearts, the game keeps going until I lose the 5 invisible.

Joe123
03-02-2009, 11:18 AM
global script Slot2{
void run(){
while(true){
//other global functions go here

if(Link->HP <= 5*16) Link->HP = 0;
Waitframe();
}
}
}

CaRmAgE
03-02-2009, 11:33 AM
And maybe you can and I just didn't realise.
Why would you need to?

Having braces just by themselves in C allows you to limit the scope of variables declared inside the braces. Not sure what use it would have in Zscript, though...

Joe123
03-02-2009, 11:50 AM
Aha, that makes sense.
That application would stretch to ZScript as well, if you can do that in ZScript.

ShadowTiger
03-02-2009, 12:09 PM
Incidentally, we should have a slot 4 global script that triggers on Link's death. It would get to run for one frame, and if Link's HP is still zero after that, he dies for real.Man, I have recommended that SO many times... I think this is just something ZC should naturally have. It can be so very useful...

I mean even having it check to see whether Link's Health is near .0001% health is entirely impractical because there are attacks which do just enough damage to bypass that critical checking point. So it'd be something like, if(Link->HP <= 1%(Link->MaxHP){etc} or whatever it'd be. (Never was too clear on the syntax.) and that'd work just fine, because it'd also be able to accommodate Link being at less than zero health.

Joe123
03-02-2009, 12:51 PM
I mean even having it check to see whether Link's Health is near .0001% health is entirely impractical because there are attacks which do just enough damage to bypass that critical checking point. So it'd be something like, if(Link->HP <= 1%(Link->MaxHP){etc} or whatever it'd be. (Never was too clear on the syntax.) and that'd work just fine, because it'd also be able to accommodate Link being at less than zero health.

What're you trying to suggest here :confused:

Link's health is an integer value I believe.

ShadowTiger
03-02-2009, 07:48 PM
I'm just reiterating what I had quoted.


It would get to run for one frame, and if Link's HP is still zero after that, he dies for real. To give the game at least one frame of confirmation that Link's Health really is at zero before giving the game over screen, to allow scripts to run or restore his health and do whatever else the scriptmaker wants it to do. I had no intention of mentioning value types.

Joe123
03-03-2009, 01:33 PM
Oh wait you have '1%Link->MaxHP' rather than '1/Link->MaxHP'.
I thought you'd put a back-slash, and in which case you'd have a value smaller than one. In which case, if the integer value is less then a number smaller than one then it has to be zero anyway, so you may as well have put 0. So this is why I'm confused.

ShadowTiger
03-03-2009, 02:55 PM
Now I'm confused too.

Okay. Let's backtrack. Let's not think of any C++ here. Let's think of the practical, pragmatic purposes for the discussion here.

We need a single frame between Link's HP being 0 or whatever, and the Game Over screen. Let's talk about that, please? I'm seriously getting confused and bewildered that nothing I'm saying is getting across with any sign of acknowledgment.

Joe123
03-03-2009, 05:05 PM
Oh, sorry.
I agree that we should have a global script that runs when Link dies, but I know full well that I'm not currently capable of adding that in in the slightest.

I wasn't sure whether you were suggesting that line of code to be added into a script, or into ZC's code itself.
'cause it wouldn't really be much use actually in ZC. I'm pretty sure (althought I may well have missed it) that there isn't even a Link object in ZC's code.
I know I'm just being pedantic there (there is a LinkData object), but even so it'd be a lot more complicated than that.