2012-02-19 19:16:30

I don't know what I'm doing wrong but I can't get my bgt script to run. It is tell me that there is a problem with a function that doesn't look like it could be wrong in any way. It doesn't seem to like some of the if statements I use and I have no idea why. The errors I seem to get seem to say Unexpected token 'if'. The function is posted below.

    void view_in(int point)
{
int v;
v = 50;
if (point == left && player_x > 0)
{
for (int i = 1; i <= v; i++)
{
if (player_x-i < 0)
{
return;
}
else
        {
        if (map[player_x-i][player_y] == "pit")
            {
            wait(5);
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 100, true);}
wait(5);
}
if (map[player_x-i][player_y] != "nothing")
{            
speech.speak(map[player_x-i][player_y]);
while(speech.speaking)
{
wait(5);
}            
return;
}        
else    
{
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 200, true);
wait(2);
}        
}    
}
}
if (point == right && player_x < x_boundary)
        {        
for (int i = 1; i <= v; i++)
            {
            if (player_x+i > x_boundary)
{
return;
                }                
else
{
if (map[player_x+i][player_y] == "pit")
{
wait(5);
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 100, true);
wait(5);
}
if (map[player_x+i][player_y] != "nothing")
{
speech.speak(map[player_x+i][player_y]);
while(speech.speaking)
{
wait(5);
}
return;
}
else
{
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 200, true);
wait(2);
}
}
}
}
if (point == forward && player_y < y_boundary)
{
for (int i = 1; i <= v; i++)
{
if (player_y+i > y_boundary)
{
return;
}
else
{
if (map[player_x][player_y+i] == "pit")
{
wait(5);
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 100, true);
wait(5);
}
if (map[player_x][player_y+i] != "nothing")
{
speech.speak(map[player_x][player_y+i]);
while(speech.speaking)
{
wait(5);
}
return;
}
else
{
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 200, true);}
wait(2);
}
}
}
if (point == back && player_y > 0)
{
for (int i = 1; i <= v; i++)
{
if (player_y-i < 0)
{
return;
}
else
{
if (map[player_x][player_y-i] == "pit")
{
wait(5);
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 100, true);
wait(5);
}
if (map[player_x][player_y-i] != "nothing")
{
speech.speak(map[player_x][player_y-i]);
while(speech.speaking)
{
wait(5);
}
return;
}
else
{
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 200, true);}
wait(2);
}
}
}
if (point == forwardright)
{
if (player_x < x_boundary && player_y < y_boundary)
{
for (int i = 1; i <= v; i++)
{
if (player_x+i > x_boundary && player_y+i > y_boundary)
{
return;
}
else
{
if (map[player_x+i][player_y+i] == "pit")
{
wait(5);
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 100, true);
wait(5);
}
if (map[player_x+i][player_y+i] != "nothing")
{
speech.speak(map[player_x+i][player_y+i]);
while(speech.speaking)
wait(5);
}
return;
}
else
{
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 200, true);
wait(2);
}
}
}
if (point == forwardleft)
{
if (player_x > 0 && player_y < y_boundary)
{
for (int i = 1; i <= v; i++)
{
if (player_x-i < 0 && player_y+i > y_boundary)
{
return;
}
else
{
if (map[player_x-i][player_y+i] == "pit")
{
wait(5);
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 100, true);
wait(5);
}
}
if (map[player_x-i][player_y+i] != "nothing")
{
speech.speak(map[player_x-i][player_y+i]);
while(speech.speaking)
{
wait(5);
}
return;
}
else
{
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 200, true);
wait(2);
}
}
}
if (point == backleft)
{
if (player_x > 0 && player_y > 0)
{
for (int i = 1; i <= v; i++)
{
if (player_x-i < 0 && player_y-i < 0)
{
return;
}
else
{
if (map[player_x-i][player_y-i] == "pit")
{
wait(5);
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 100, true);
wait(5);
}
if (map[player_x-i][player_y-i] != "nothing")
{
speech.speak(map[player_x-i][player_y-i]);
while(speech.speaking)
{
wait(5);
}
return;
}
else
{
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 200, true);
wait(2);
}
}
}
}
}
if (point == backright)
{
if (player_x < x_boundary && player_y > 0)
{
for (int i = 1; i <= v; i++)
{
if (player_x+i > x_boundary && player_y-i < 0)
{
return;
}
else
{
if (map[player_x+i][player_y-i] == "pit")
{
wait(5);
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 100, true);
wait(5);
}
if (map[player_x+i][player_y-i] != "nothing")
{
speech.speak(map[player_x+i][player_y-i]);
while(speech.speaking)
{
wait(5);
}
return;
}
else
{
sounds.play_stationary_extended("sounds/short_sound1.wav", false, 0, 0, 90, 200, true);
wait(2);
}
}
}
}
}
}
}
All that is gold does not glitter, Not all those who wander are lost; The old that is strong does not wither, Deep roots are not reached by the frost. From the ashes a fire shall be woken, A light from the shadows shall spring; Renewed shall be blade that was broken, The crownless again shall be king.
DropBox Referral

2012-02-19 19:46:01 (edited by CAE_Jones 2012-02-19 19:46:46)

If it says unexpected 'if', then it thinks you're not inside a function or method. This means one of two things (or maybe others I can't think of):
- Something is unclosed before the function, and closes inside of it, so the line that indicates that it is a function is overlooked.
- There's something extra (probably a brace) inside the function that makes it appear closed early.

Either one is annoying to track down, but if it's the first one, looking in the function itself won't provide the answer, unfortunately.
If you save the function in a separate file and run that file through my matcher script, it should let you know if there's something extra in the function, or if something's missing.
If you have something really large, I'd recommend copying it into the file to be debugged, and removing sections until you can track down the problem. That's helped me find problems much faster than trying to look through the code line by line would have (and when you do that, it's easy to filter stuff out and miss it anyway).

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2012-02-19 20:24:50

I took all the functions out of the main script and put them in to their own files. Then I ran each file against your matcher script. Still no unmatched anything. The good thing is that I have the function that giving me problems in its own file. This should mean that I can move the function in to a safe place and start debugging again. This is one thing I like about bgt over basic on the braille lite. I can have the code spread out in to different files if needed.

All that is gold does not glitter, Not all those who wander are lost; The old that is strong does not wither, Deep roots are not reached by the frost. From the ashes a fire shall be woken, A light from the shadows shall spring; Renewed shall be blade that was broken, The crownless again shall be king.
DropBox Referral

2012-02-19 20:37:09

I ran it in Blast buddy and it says that line 155 "while(speech.speaking)" is missing an open bracket.  Also when viewing tier zero it starts showing IF statements, meaning you have an extra closed bracket somewhere before the IF statement on line 37 "if (point == right && player_x < x_boundary)".  Actually when I removed a bracket it still had some messed up tiers, so I think there are multiple spots missing brackets throughout the program.

- Aprone
Please try out my games and programs:
Aprone's software

2012-02-19 23:11:04

Thanks for all the help. it turns out that I misplaced some brases.

All that is gold does not glitter, Not all those who wander are lost; The old that is strong does not wither, Deep roots are not reached by the frost. From the ashes a fire shall be woken, A light from the shadows shall spring; Renewed shall be blade that was broken, The crownless again shall be king.
DropBox Referral