Jump to content

Photo

My script keeps freezing the game.. Help/Suggestions?


  • Please log in to reply
16 replies to this topic

#1 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 06:47 PM

Spoiler



Okay, so I just started learning anything about scripting and coding like 2 days ago, so I'm very nooby. This is just a "test" script of what I'm trying to do. I'm trying to make it so when you stand on a certain spot, you play Ocarina notes (I've got the ocarina notes SFX on my qst) and play the Song of Time. I don't know what is wrong with this... It compiles and everything, but it freezes up when I enter the room. Any suggestions? Sorry I'm so nooby.. I literally just starting doing this and I'm trying my best. Basically, all the script is doing is if you play the notes in the right order, (or press B to quit) it will play the song, and do whatever I end up adding to the end of it. But it just keeps freezing no matter what I do.. I'm guessing I messed up the "for" loop somehow, but I think I have Waitframe()'s everywhere they need to be, don't I? Thanks in advance!! :)

#2 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 06:48 PM

Woah, that code looks sloppy and hard to read on here... How do I make it look better? It's spaced out really neatly on the Notepad file. o:

#3 Mitchfork

Mitchfork

    no fun. not ever.

  • Members
  • Real Name:Mitch
  • Location:Alabama

Posted 12 May 2013 - 06:52 PM

You can put the code in code brackets, like so:
//code here

I can't look too hard at this since I'm on my phone, but if you're getting freezing problems you're probably missing a Waitframe(); somewhere.

EDIT:didn't read your post fully, sorry. I'll try to help you out once I get on my actual computer if nobody else does.

#4 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 06:55 PM

//import "std.zh"

ffc script OcarinaLoop
{
void run(int SFX1, int SFX2, int SFX3, int SFX4, int SFX5, int SONGCOMPLETE)
{
Screen->Message(2);
while(true);
{
while(Abs(Link->X - this->X) < 4 && Abs(Link->Y - this->Y) < 4)
{
int SOTNOTES;
for(SOTNOTES = 0; SOTNOTES == 6;)
{
if(Link->InputA)
{
Link->InputA = false;
Game->PlaySound(SFX1);
if((SOTNOTES == 1) || (SOTNOTES == 4))
{
SOTNOTES += 1;
}
else
{
SOTNOTES = 0;
}
}
if(Link->InputUp)
{
Link->InputUp = false;
Game->PlaySound(SFX2);
SOTNOTES = 0;
}
if(Link->InputDown)
{
Link->InputDown = false;
Game->PlaySound(SFX3);
if(SOTNOTES == 2 || SOTNOTES == 5)
{
SOTNOTES += 1;
}
else
{
SOTNOTES = 0;
}
}
if(Link->InputRight)
{
Link->InputRight = false;
Game->PlaySound(SFX4);
if(SOTNOTES == 0 || SOTNOTES == 3)
{
SOTNOTES += 1;
}
else
{
SOTNOTES = 0;
}
if(Link->InputLeft)
{
Link->InputLeft = false;
Game->PlaySound(SFX5);
SOTNOTES = 0;
}
if(Link->InputB)
{
Quit();
}
if(SOTNOTES == 6)
{
Game->PlaySound(SONGCOMPLETE);
Quit();
}
Waitframe();
}
Waitframe();
}
Waitframe();
}
Waitframe();
}
}
}

Should I just start putting waitframes everywhere until it stops? I just don't get it, because I have a waitframe for every loop. o:

#5 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 06:58 PM

Sorry to keep spamming comments, but do I need a Waitframe for each "if" section of a for loop?

#6 Mitchfork

Mitchfork

    no fun. not ever.

  • Members
  • Real Name:Mitch
  • Location:Alabama

Posted 12 May 2013 - 09:42 PM

You can avoid posting multiple times by just hitting the edit button in the bottom-right of your post. :)

So reading through this there are a couple of things that I found wrong with it... one is your use of a for() loop.  First, the syntax is wrong... the way that a for() loop iterates is by looping until a specific variable meets a condition, and it alters that variable in some way between each loop.  You don't have any statement to alter the SOTNOTES variable each time you loop.  For example:
this

for(SOTNOTES = 0; SOTNOTES == 6;)
should be something like this
for(SOTNOTES = 0; SOTNOTES == 6;SOTNOTES++)
However, it doesn't look like you want a for() loop at all; you want the loop to keep going indefinitely until SOTNOTES equals 6, which you're manually changing via code. So you should instead try replacing it with
while(SOTNOTES < 6)

So the first place where you're going to have a problem is
Screen->Message(2);
You need a Waitframe(); after this line.  Generally speaking, whenever you want something to happen on-screen, put in a Waitframe.  You want a message to appear, so you have to wait a frame for it to start going.  That should fix your immediate problem, but there's definitely going to be more debugging after this as far as I can tell... but I'll let you sort it out (and feel free to keep asking questions!).

You also had what appeared to be a bracketing error that I took care of... I recommend using Notepad++ or some other dedicated programming/scripting text editor because those will highlight brackets for you and help in the debug process. :) Here's my (untested) edits to your script:

script

  • MrPandaPenguin likes this

#7 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 10:05 PM

Oh, wow! Thank you so much! I wasn't expecting such a helpful reply. :) Yeah, I didn't even realize that I should just use a while loop with the < 6 part in it. The code only had one mistake, you left the semicolon in the () of the while loop, but I don't really consider that a mistake. Haha. :) But, sadly.. it still froze on me.. I don't understand how that is, because there's even an extra waitframe at the bottom... Hmmmm...Just btw, I'm super grateful of how helpful you're being! :) And might I ask how exactly you made the code look so neat? I don't know anything about posting fancy stuff on forums. Haha.

 

EDIT: I also noticed.. It seems that the only efficient way for me to stop the freezing it to get rid of the while(true) in the start of it all...

 

EDIT2: But when I delete the while(true) and test it, the loop for playing the song doesn't work... I just walk right over it.. I once almost got it to work, but not it won't do what I want it to do..


Edited by MrPandaPenguin, 12 May 2013 - 10:17 PM.


#8 grayswandir

grayswandir

    semi-genius

  • Members

Posted 12 May 2013 - 10:18 PM

while(true);

 

 

Assuming zscript works like C, that line will loop forever. While loops will execute the next command while their condition remains true. Normally, you'd use brackets "{ ... }" to make the next command more than one thing. This, however, has the next command as the empty statement ";", which it will keep executing forever.

 

Basically, get rid of that semicolon.


  • MrPandaPenguin likes this

#9 Mitchfork

Mitchfork

    no fun. not ever.

  • Members
  • Real Name:Mitch
  • Location:Alabama

Posted 12 May 2013 - 10:19 PM

Oh, duh! :doh: Good catch, I'm really horrible at little things like that.  I've been staring at this for about 10 minutes wondering what was going on.



#10 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 10:22 PM

I leave it semicolons constantly, so I'm glad the compliler lets me know. Haha. :) So have I.. I really don't understand what's freezing it up! I know a way I could write the code that would work, but holy crap would it be way bigger than it needs to be. xD

 

EDIT: Like.. It's completely understandable if somewhere in the SOTNOTE section that something wouldn't work, but I'm failing to see the reasoning behind it still freezing, you know? And IF the freezing HAPPENS to be that it's somehow initiating it right when I enter and all my inputs are returning "false", then there would at least be the SFX playing too.. So the problem has to be linked to something else, I think..


Edited by MrPandaPenguin, 12 May 2013 - 10:26 PM.


#11 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 10:29 PM

while(true);

Assuming zscript works like C, that line will loop forever. While loops will execute the next command while their condition remains true. Normally, you'd use brackets "{ ... }" to make the next command more than one thing. This, however, has the next command as the empty statement ";", which it will keep executing forever.

 

Basically, get rid of that semicolon.

 

 

I didn't even notice this post until just now! And I will try that right away! I didn't even notive that I had a semicolon after the while(true)!



#12 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 10:32 PM

I love you, grayswandir. Thank you for having such a brilliant eye for semicolons because I would have never noticed that. I'm surprised the compliler doesn't consider that an error because that would cause nothing but your game freezing. Haha. THANK YOU SO MUCH! The only problem is that when I play the song sequence, it doesn't quit. BUT I CAN FIX THAT! I'm on the road to success! Thank you so much. :)



#13 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 12 May 2013 - 11:01 PM

One more question, if anyone would like to take a the time to help. :) I got everything to work pretty much. You press the buttons, and they all make the right notes and everything, but it doesn't quit or play the SONGCOMPLETE SFX when I do the sequence of notes that add the SOTNOTES up to 6. I hope that makes sense. Sorry for asking so many questions!



#14 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 13 May 2013 - 09:11 PM

You've got a large group of Waitframe() commands there, and I'm pretty sure that you don't need more than one. At last, I was told not to use more than one, as the script terminates on the first instance of reaching a Waitframe(); it functions exactly as void(quit) inside anything other than a global script. Beyond that, I think that you may want to do this:

while(SOTNOTES <= 6;) 
in the place of
while(SOTNOTES < 6;)
 
and
 
 if(SOTNOTES == 6) 
may need to be
else if (SOTNOTES == 6)
 
Its placement seems to be part of a series of if arguements for playing the notes and accumulating them and is also inside the same while loop as
while(SOTNOTES < 6;)
.
 
I would imagine that you need it either outside of that while loop or it needs to be an else arguement, although this is merely based on my observation at a glance.
 
I'm curious on how you'll use this when you have it working... I am looking to eventually do a customised transmat/teleporter with access codes to visit spcific destinations, and that falls into similar territory to this.

Edited by ZoriaRPG, 13 May 2013 - 09:16 PM.


#15 MrPandaPenguin

MrPandaPenguin

    Newbie

  • Members

Posted 14 May 2013 - 02:58 PM

You've got a large group of Waitframe() commands there, and I'm pretty sure that you don't need more than one. At last, I was told not to use more than one, as the script terminates on the first instance of reaching a Waitframe(); it functions exactly as void(quit) inside anything other than a global script. Beyond that, I think that you may want to do this:
 

while(SOTNOTES <= 6;) 
in the place of
while(SOTNOTES < 6;)
 
and
 
 if(SOTNOTES == 6) 
may need to be
else if (SOTNOTES == 6)
 
Its placement seems to be part of a series of if arguements for playing the notes and accumulating them and is also inside the same while loop as
while(SOTNOTES < 6;)
.
 
I would imagine that you need it either outside of that while loop or it needs to be an else arguement, although this is merely based on my observation at a glance.
 
I'm curious on how you'll use this when you have it working... I am looking to eventually do a customised transmat/teleporter with access codes to visit spcific destinations, and that falls into similar territory to this.

 

Spoiler

 

Hey! Yeah, I got it to pretty much work fully with what I wanted it to do. :) I was basically trying to make a script that would play the Song of Time and open the Door of Time. Everything works fine in it except for one little thing (which is kind of hard to explain) ..Lets see, how do I put this? You still have to play the notes in the correct order, but it allows you to press the current note that you're on in the sequence as many times as you want without messing up the sequence. It isn't much of a problem, because you still can't hit the wrong notes, so I'm happy with it. c: But yeah! There are lots of other cool things I could try using it for too.. I kind of wanted to try to make an item that replicates the Ocarina of Ocarina of Time, but we'll see where that will go. :) Currently, this script just activates the "Ocarina" playing when you're standing on the FFC, but that's just because I was basically just making a "prototype" of the Ocarina Item. c: Sorry for blabbing!

 

EDIT: I can not figure out how to make the code not look like crap...


Edited by MrPandaPenguin, 14 May 2013 - 03:27 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users