help with shooting range scoring system (SOLVED (for the most part))

Started by esper, Sat 27/01/2007 23:12:04

Previous topic - Next topic

esper

Help!

I've just finished working on a shooting gallery for my new Alpha - X game where your character can practice his shooting skills before going out into the real world. Your robotic assistant is supposed to tell you how you did when you leave the range. Here's how I coded it:

Code: ags

if (GetGlobalInt(496)==1) {
  if (GetGlobalInt(499)==GetGlobalInt(498)/2) {
    spottalk("Wow, Rhys! You didn't waste a single shot! Good job!");
    return;
    }
  if (GetGlobalInt(499)-10>GetGlobalInt(498)/2) {
    spottalk("Ummm... How long have you been doing this? You sure wasted quite a few shots!");
    return;
    }
  if (GetGlobalInt(499)-5>GetGlobalInt(498)/2) {
    spottalk("Well, good job, Rhys. You missed a couple shots, but you still managed not to waste too many trigger-pulls.");
    return;
    } 
}
if (GetGlobalInt(496)==1) {
  if (GetGlobalInt(497)==GetGlobalInt(498)/2) {
    spottalk("You hit just about as many as you missed... Looks like you should try it again.");
    return;
    }
  if (GetGlobalInt(497)<GetGlobalInt(498)/2) {
    spottalk("You hit quite a few more than you allowed to get away. Good job, Rhys.");
    spottalk("Maybe just a bit more practice and you'll be ready for the real thing.");
    rhystalk("Hey, Roger! You forget, you're talking to a professional here!", 21);
    return;
    }
  if (GetGlobalInt(497)==0) {
    spottalk("Wow! You didn't let a single one get away! Those smashers had better watch their backs!");
    return;
    }
  if (GetGlobalInt(497)>GetGlobalInt(498)/2) {
    spottalk("Oh, my, Rhys. That was a terrible job! You let more get away then you even hit! Looks like it's back to the drawing board!");
    return;
    }
 }



Sorry for the messy code... That's just how I roll.
global variable 497 is the number of targets that got away from you. variable 498 is the number of hits you made (for some reason I can't quite figure out, every time you hit one of them, this score went up by two, so that's why it's divided by two here). variable 499 is the overall number of shots you've taken. This code is in the Enters Room After Fadein code, and global variable 496 is the one that tells the game you've just come from the gallery.

Anyway, I'm having hella problems getting this to work right.

--Firstly, the RETURN; code, which should just be backing you out of the conditional block, seems to be backing out of the entire rest of the code. Your robot should tell you both how you did with the number of shots and the number of hits, but after telling you the first set he doesn't tell you the second.
--Second, there's a block of code at the end of this that resets all the targets, all the timers involved with the targets, and global variables 496, 497, 498, and 499. However, when you go back to the range, you still have the same score from last time, and some targets are sometimes still on the screen.
--Tertiarily, when I took out the "return" phrase, the robot would go down the list and say a couple different things that he shouldn't have said, even though the conditionals weren't met for him to say it.

So, what am I doing wrong?
This Space Left Blank Intentionally.

GarageGothic

As far as I know, the return command will always back out of the entire function being run at the moment. I'd love it if you could just use it to "skip out" of the current set of brackets, but I don't think it's possible.

As for the second problem, it sounds more like the code which checks the GlobalInts and resets the target on room entry isn't being run properly. I don't think it's related to the code you pasted here.

Thirdly, if you remove the "return"s, you should insert some "else if"s instead of the lower "if"s - without having looked over the code, it could be possible that multiple conditionals be true at the same time.

esper

#2
Hmmm. I think I'll try taking all of this out of a single "run script" interaction and turn it into several to alleviate the problem that "return;" is causing me.

As for not doing the reset code properly... I cut and pasted it exactly from another block of code somewhere else in the program that does work, so I'm thinking it's just because it's at the end of the block of code involving all the "returns." I'll edit this as soon as I find out if that'll work or not.

EDIT: Welllll.... Close enough. It's still acting a little buggy, and there's absolutely no reason I can see for that to be so, but at least it's doing what I want for the most part. Thanks again, GG. Maybe someone should suggest either a "goto" code or a way to "return" only out of an if...else block.
This Space Left Blank Intentionally.

Ashen

I'm possibly just being a bit dense, but why do you need to quit out of the if .. else if block anyway? If the other conditons aren't met, they won't run - return; or no return;.

The only thing I can see is that you might need to rewrite, or at least reorder, the GetGlobalInt(499)-10 and GetGlobalInt(499)-5 conditions. If GlobalInt 499 is more than 10 higher than GlobalInt(498)/2, then it's obviously also going to be more than 5 higher. (The other condition. I think...) Swap the -5 and -10 conditions around, make most of the ifs into else ifs and dump the returns, and see how that works.

Also, why do you have two blocks of if (GetGlobalInt(496)==1)? (Or are these from different parts of the script?)

Beyond that, maybe you could be a bit more specific about what 'acting a little buggy' is?
I know what you're thinking ... Don't think that.

esper

I had the second if 496=1 because I was trying to get the "return" function to take me out of one block and into the next. I thought if I threw that in I could talk it into believing that return should take it there instead of completely out of the script. I didn't know at the time how return was supposed to work.

just changing the if statements into if...else statements seemed to have worked. I haven't fully tested it yet, but I think everything's okay, except maybe the -10, -5 part. We'll see. As for now, I think this problem is fixed.
This Space Left Blank Intentionally.

SMF spam blocked by CleanTalk