if not "this" or "this" then do "this"

Started by Revae, Mon 18/06/2012 06:48:52

Previous topic - Next topic

Revae

Hey folks!

I'm feeling pretty dumb at the moment.  I'm not a great scripter, and I've been stuck on this for a while.  I'd have searched for the answer but I couldn't think of a way to put it in the search field.

Problem is: I have a bartender with some rat poison behind him.  And if he's washing a glass or standing at the bar I want him to stop you from going behind the bar.  But if he's walked off then grabbing the rat poison is okay.  Like so:

function oRatPoison_PickUp(){
  if (cCharlie.View != 12 || 27){
    player.Walk(168, 577, eNoBlock, eWalkableAreas);
    player.Loop=7;
    player.LockView(4);
    player.Animate(7, 4, eOnce, eNoBlock, eForwards);
    player.UnlockView();
    oRatPoison.Visible=false;
}

  else{
    cCharlie.Say("Hey man... noone goes behind the bar but me...");
  }
}

But that doesn't work.  It just makes the rat poison invisible, skipping the player walking and regardless of Charlies view.

And I'm confused.  Any help would be rad.  Thanks!

steptoe

#1
QuoteBut that doesn't work.  It just makes the rat poison invisible, skipping the player walking and regardless of Charlies view.

If you want the player to move BEFORE the next thing happens use:

Code: ags

 player.Walk(168, 577, eBlock, eWalkableAreas); // You used eNoBlock

// If you want the player to animate BEFORE the next thing happens use:

 player.Animate(7, 4, eOnce, eBlock, eForwards); // You used eNoBlock


eNoBlock causes the script to pass on to the next line hence skipping it...


Andail

#2
Yeah, the blockable issue, plus this:

if (cCharlie.View != 12 || 27){

doesn't look right to me. You mean that if Charlies' view isn't 12 or 27, you want the following to execute?
Well, now you're not saying "if neither this nor that", you're saying "if not this, but if this". You need a negative operator after the ||, or enclose both numbers with ().

Revae

Red Belly - How could I not see that.  Thanks!

Andail - Ohhhhh.  I didn't know that.  The "()" is optional from what I've read, but recommended...  So I spose I'll test that out now...

Revae

Hmm...  Didn't work.  Either way, with () or without.

Andail

#5
If you must use two negative, try
if ((cCharlie.View != 12) && (cCharlie.View != 27)) {

This means that if the character Charlie is in either view 12 or view 27, the rest won't execute.

PS:
I think you're confusing the || with how you say "or" in common speech; "not this or this". However, in the script syntax this should be read as "if not this, or if this".

JJS

It is strange that (12 || 27) even compiles because I have a hard time figuring out what it could mean to the compiler.

In C (12 | 27) would be a bitwise OR which makes sense, but (12 || 27) would be a boolean OR. I guess the compiler sees both values as TRUE (i.e. not 0) and generates a TRUE by OR-ing the two TRUE values together. Then it casts the boolean to an int (1) for the comparison with the View. I suppose the if-branch always runs unless View is 1.
Ask me about AGS on PSP, Android and iOS! Source, Daily builds

Khris

JJS: Yes, that's exactly what happens.

Revae:
AGS requires you to state multiple conditions in their entirety.

You don't need additional brackets though:
Code: ags
  if (cCharlie.View != 12 && cCharlie.View != 27)

Revae

Hey! Thanks everyone.  This has got to be the most helpful internet community in existence.  I particularly like the added conversation about details I didn't ask.  Helps to learn.

Andail - I definitely am thinking of it too grammatically.  Bad habit I'm sure, but I'm a-learnin'.  I'll pop in what you said when I get home, and hopefully it'll function properly.  (I can't imagine why it wouldn't). Gracias.

I'd done some scripting in the past, but this requires more than I've ever needed to know before, so it's getting tricky.  It's probably really messy too, but I don't think I'm going to clean any of it until I get it functioning at least.

SMF spam blocked by CleanTalk