do an action once and not be able to repeat it? (SOLVED unless you know better)

Started by Mixand, Wed 19/05/2010 17:36:34

Previous topic - Next topic

Mixand

I have my character peeing into the toilet but you can click it over and over again. With an object it could check if you have the object already but this is something I've done. How can I make it so I can only pee once only?

Thanks

(Here's the coding)

function hJtoilet_Interact()

{
   cJason.Walk(150, 105, eBlock, eWalkableAreas);
   Display("You go to the toilet.");
   cJason.ChangeView(4);
   Wait(70);
   cJason.ChangeView(1);

}

barefoot

#1
you could end the script by disabling the hotspot to stop it activating again.

Code: ags

hJtoilet.Enabled = false;


Or use HasInventory

Code: ags

{
  if (player.HasInventory(object)) {
    (do this);
  }
  else (do this);
}



barefoot
I May Not Be Perfect but I Have A Big Heart ..


Dualnames

Code: ags

function hJtoilet_Interact(){
    cJason.Walk(150, 105, eBlock, eWalkableAreas);
if (Game.DoOnceOnly("peewhee")) {
    Display("You go to the toilet.");
    cJason.ChangeView(4);
    Wait(70);
    cJason.ChangeView(1);
return;
}
    Display("You've been there. Enough.");
}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ryan Timothy B

I really don't think you should be getting into that habit with using return, Duals.  It could possibly lead to confusion and/or errors in your code.
Not that I've gone to school for programming to learn the do's and don'ts.  But I believe it should be done like this instead:

Code: ags

function hJtoilet_Interact()
{
  cJason.Walk(150, 105, eBlock, eWalkableAreas);
  if (Game.DoOnceOnly("peewhee"))
  {
    Display("You go to the toilet.");
    cJason.ChangeView(4);
    Wait(70);
    cJason.ChangeView(1);
  } 
  else  //you've already done it, so it runs the else.
  {
    Display("You've already emptied your bladder.");
  }
}

Dualnames

I love the return thing. The best thing ever happened to me is that command solely. :D
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

I have to say, it makes me feel a bit uneasy, too :)

On the other hand, let's look at the standard Abs implementation:
Code: ags
int Abs (int a) {
  if (a < 0) return -a;
  return a;
}

This doesn't look "unclean" although technically, it does the same thing.

Dualnames

Unless I'm mistaken in a terrible way, and luck has come through and worked on every single script of every game/module/whatevery thing I coded, return, breaks the script at that point it is placed and is also used for returning values, and some other gimmicks.

You all use return on dialogs don't you? It's just  a way to avoid "elses" which are probably great for the rest of you, but for me they always worked just barely wrong, so I'm glad I'm using return. Perhaps it's not a great thing to overdo it, I know  :D, but I think I'm adept to its use.

Speaking of the code in question, I'd probably use Ryan's.
As for my code 100% sure it will do the following actions:
1. Run the functions inside the if statement, then change Jason view to 1 and stop.

The second time and every other time, it will simply display the message (apparently walking there first)   
How does it give the idea that it will eventually break?

I get the unclean thing, well, I've had some performance issues with HHGTG, I can't say i haven't, but this code looks okay to me.  :-\
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ryan Timothy B

I understand what a return does.
Although, I'm not exactly sure what a return does in something like Rep_ex.  If it's written inside an IF statement within the Rep_ex, does it abort the IF statement and continue on with the Rep_ex code, or completely abort the Rep_ex?


But anyway, I meant possible errors in your code, as in: it's harder to notice that you've missed out on a return than it is to notice a missing else.  It's also neater and less confusing logic with else's.

It's basically just less chances for screw ups, and especially since your posting code in the beginners forum, I'd try to stick to else's just so it's not as confusing for any new comers.  But hey, that's just the way I look at it. :P

Dualnames

Quote from: Ryan Timothy on Thu 20/05/2010 18:44:54
I understand what a return does.
Although, I'm not exactly sure what a return does in something like Rep_ex.  If it's written inside an IF statement within the Rep_ex, does it abort the IF statement and continue on with the Rep_ex code, or completely abort the Rep_ex?

It aborts the rep_exec, but just for one time, not permanently.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk