PDA

View Full Version : FFC help needed...



lucas92
07-28-2008, 12:39 PM
Alright, I've got this:


ffc script guard_move_vertical
{
void run (int ffcnumber, int string, int string2, int item1, int item2)
{
int X;
int Y;
float X;
float Y;
int Dir;
int Wait;
float Ay;
ffc guard;
Screen->LoadFFC(ffcnumber);
guard->Flags [2];
bool Item;


if (Link->Y<96)
{
guard->Y==96;
}
else
{
guard->Y==Link->Y;
}
if (Link->X==guard->X-16)
{
Screen->Message(string);
if (Link->Item[item1]==true && Item[item2]==true)
{
for (Wait==0;Wait==128;Wait++)
{
Waitframe();
}
Screen->Message(string2);
while (guard->Y!=96)
{
guard->Ay==-1;
}
}
else
{
Link->Dir==2;
Link->X==guard->X-32;
}
}
}
}


But there's one problem:
http://i169.photobucket.com/albums/u231/lucas92_rct2/Problme4.png

Also, I would want to know how to make a ffc solid because I really doubt that with my method, it would make it solid...

Oh, the script is basically a guard that is blocking the way to Link if he doesn't has the first sword and a shield, a little bit like the guy blocking the way to Link in Ocarina of Time. So, if Link has the first sword and shield, the guy moves up and stay at one location, so he let pass Link.

oh, and this post is only a copy and past from PureZC board from my topic learning Zscript...

C-Dawg
07-28-2008, 01:17 PM
You can't have both a float and an int called the same thing. In your script, you declare "int X;" and "float X;". Same for Y. You can't do that.

As to faking solidity, just get Link's input and location. If Link is close to the FFC (within 16 pixels) and on the side opposite of where he's moving, cancel Link's input or shove link back 1 pixel, whatever.

lucas92
07-28-2008, 02:10 PM
ffc script guard_move_vertical
{
void run (int ffcnumber, int string, int string2, int item1, int item2, int data)
{
bool InputUp;
bool InputDown;
bool InputLeft;
bool InputRight;
bool Item;
float X;
float Y;
int Dir;
int Wait;
float Ay;
ffc guard;
Screen->LoadFFC(ffcnumber);

if (Link->X==guard->X-16 && Link->Y==guard->Y)
{
Link->InputRight==false;
}
if (Link->X==guard->X+16 && Link->Y==guard->Y)
{
Link->InputLeft==false;
}
if (Link->Y==guard->Y-16 && Link->X==guard->X)
{
Link->InputDown==false;
}
if (Link->Y==guard->Y+16 && Link->X==guard->X)
{
Link->InputUp==false;
}
if (Link->Y<96)
{
guard->Y==96;
}
else
{
guard->Y==Link->Y;
}
if (Link->X==guard->X-16)
{
Screen->Message(string);
if (Link->Item[item1]==true && Item[item2]==true)
{
for (Wait==0;Wait==128;Wait++)
{
Waitframe();
}
Screen->Message(string2);
while (guard->Y!=96)
{
guard->Ay==-1;
}
}
else
{
Link->Dir==2;
Link->X==guard->X-32;
}
}
}
}


Ok, I'm surely doing something wrong...

http://i169.photobucket.com/albums/u231/lucas92_rct2/Problme5.png

He's not even moving or anything... :(
I think I need some help... Could the drawtile void be helping me? I don't figure it out...

C-Dawg
07-28-2008, 03:58 PM
Well, you've a few issues.



if (Link->X==guard->X-16 && Link->Y==guard->Y)
{
Link->InputRight==false;
}
if (Link->X==guard->X+16 && Link->Y==guard->Y)
{
Link->InputLeft==false;
}
if (Link->Y==guard->Y-16 && Link->X==guard->X)
{
Link->InputDown==false;
}
if (Link->Y==guard->Y+16 && Link->X==guard->X)
{
Link->InputUp==false;
}


In this section, you've got two problems. First, you're only checking if Link is EXACTLY 16 pixels away from the guard. When Link runs, he moves 1 pixel, 1 pixel, then 2 pixles, then repeats (or something like that). So it might be possible for him to avoid ever being EXACTLY 16 pixels away. Change it to check if Link is 16 pixels OR LESS away from the enemy.

Second, you don't really mean "Link->InputUp == false;". Two equals signs, "==" just compares the value of two things and returns the result. So when the compiler sees "Link->InputUp == false;", it just checks if Link->InputUp actually equals false or not, and then moves on because there's nothing to do with the result. Normally you'd use "==" inside an if statement, where the result would be used to determine whether the if statement executes.

What you want is "=," which ASSIGNS the value on the right into the variable on the left. So you want to say "Link->InputUp = false;".



if (Link->Y<96)
{
guard->Y==96;
}
else
{
guard->Y==Link->Y;
}


Once again, you're using "==" instead of "=."

lucas92
07-28-2008, 05:26 PM
Ok, scrap that script, here's a simpler one:


ffc script solidobject
{
void run (int Data, float X, float Y, int ffcnumber)
{
ffc solidobject;
solidobject = Screen->LoadFFC(1);
bool InputDown;
bool InputRight;
bool InputUp;
bool InputLeft;
if (Link->X<=solidobject->X-16)
{
Link->InputRight=false;
}
if (Link->X>=solidobject->X+16)
{
Link->InputLeft=false;
}
if (Link->Y<=solidobject->Y-16)
{
Link->InputUp=false;
}
if (Link->Y>=solidobject->Y+16)
{
Link->InputDown=false;
}
}
}

I'm not even able to make it a solid object, it just draw a tile with no solidity an another time... :(

Elmensajero
07-28-2008, 08:44 PM
The main reason why this doesn't work is because it isn't continuously running (if I understand scripting right). You need a while loop and a Waitframe() to get it to do anything. Second, lets look at the first if statement. It checks to see if Link is at least 16 pixels to the left of the FFC. However, this is anywhere on the screen above or below the FFC as long as that condition is met, so if Link is on that side, he won't be able to move to the right anymore. Similar things happen with the rest of the if statements. You need to check whether Link is in a certain specific position, and if so, then disable his movement. Here is the script redone so it works...


import "std.zh"

ffc script solidobject
{
void run (int Data, float X, float Y, int ffcnumber)
{
ffc solidobject;
solidobject = Screen->LoadFFC(1);
bool InputDown;
bool InputRight;
bool InputUp;
bool InputLeft;

while(true)
{
//First test if user is pressing "right" and Link is starting to walk on top of the object.
if (Link->InputRight && Link->X>=this->X-16 && Link->X<=this->X && Link->Y>this->Y-16 && Link->Y<this->Y+16)
{
Link->InputRight=false;
Link->X=this->X-16;
Link->Dir=DIR_RIGHT;
}

//Next test for when user presses "left".
if (Link->InputLeft && Link->X>=this->X && Link->X<=this->X+16 && Link->Y>this->Y-16 && Link->Y<this->Y+16)
{
Link->InputLeft=false;
Link->X=this->X+16;
Link->Dir=DIR_LEFT;
}

//Next test for when user presses "up".
if (Link->InputUp && Link->Y>=this->Y && Link->Y<=this->Y+16 && Link->X>this->X-16 && Link->X<this->X+16)
{
Link->InputUp=false;
Link->Y=this->Y+16;
Link->Dir=DIR_UP;
}

//Finally, test for when user presses "down".
if (Link->InputDown && Link->Y>=this->Y-16 && Link->Y<=this->Y && Link->X>this->X-16 && Link->X<this->X+16)
{
Link->InputDown=false;
Link->Y=this->Y-16;
Link->Dir=DIR_DOWN;
}

Waitframe();
}
}
}

Using the "this" object lets you put as many FFC's down as you want with this single script attached, and all of them will prevent Link from walking over them. Also note that the things inside run() and the ffc variable and bool variables are not necessary, I just kept them there in case you had them there for a reason. Editing Link->Dir makes it so that even though Link doesn't move onto the FFC, he still looks toward it when the button is pressed in that direction.

lucas92
07-28-2008, 09:38 PM
Really, this made my day. So while (true) check if the script is working and this-> refers to to this ffc? Really, big thanks for your help. :)

I might not have to scrap my original script at all. :p

Elmensajero
07-28-2008, 10:48 PM
Glad to be of help :D

while(true) {} is basically an infinite loop, which normally is a bad thing in any sort of programming, but quite useful in scripting. I think the way it works is that the FFC script is run only once: when Link enters the screen that the FFC is located on. However, if a while loop is used with a waitframe() function at the end of it, everything inside of it will be run once for each frame. So you put all of your initialization stuff before the while loop, and stuff you want to run the whole time Link is on the screen inside the while loop. The script is forced to end when Link leaves the screen (unless FFC's carryover, I don't understand how that works yet).

If you need help with your original script, just let me know.

pkmnfrk
07-30-2008, 04:21 AM
I would just like to jump in and point out that there is no need to declare the "bool InputUp" variables, etc. They are not used anywhere, and the compiler should be complaining about that.

Elmensajero
07-30-2008, 06:00 PM
I would just like to jump in and point out that there is no need to declare the "bool InputUp" variables, etc. They are not used anywhere, and the compiler should be complaining about that.

I mentioned this before as well :D

Also note that the things inside run() and the ffc variable and bool variables are not necessary, I just kept them there in case you had them there for a reason.
The compiler did not give me any warnings though, prob. since the compiler is a little different than a normal C/C++ compiler. I think it just adds space for the vars to the runtime stack and doesn't really care whether they are used or not.

pkmnfrk
07-30-2008, 06:27 PM
Hmm, I thought I saw warnings about unused vars before. Testing it right now, though, I guess not.

Well, then, in that case, I'm just going to go over here. <_<