Post new topic    
Page «  1, 2
Metal King Slime
Send private message
 
 PostTue May 21, 2013 7:50 pm
Send private message Reply with quote
You can directly set a tag with an NPC (other than its one-time use tag), but you can attach a textbox or a script to it that sets a tag. On the other hand maybe you only want the barrel to be activated from one direction? You ought to at least check all of the space, enter and ctrl keys though. And I meant that the check should go in the skipping scripts, like this:

Code:
script, brigand skip checks, begin
   if (hero X(me) == 31 && hero Y(me) == 14) then (
      if (key is pressed(key:space) || key is pressed(key:enter) || key is pressed(key:ctrl)) then (
         set tag (25,on)
      )
   )
   if (current map <> 7 || check tag(25)) then (
      skipping waits := true
   )
end

script, skippable wait, ticks, begin
   while (skipping waits == false && ticks > 0) do (
      brigand skip checks
      wait(1)
      ticks -= 1
   )
end

script, skippable wait for npc, npc, begin
   while(skipping waits == false && npc is walking(npc) == true) do (
      brigand skip checks
      wait(1)
   )
end


I looked over the scripts again, but can't see why it would freeze. Maybe changing the above will fix it. Did you make any changes to any of the other scripts?

Edit: fix scripts after the HTML parser ate them :(
Slime Knight
Send private message
 
 PostTue May 21, 2013 8:36 pm
Send private message Reply with quote
I had made some changes, I went through and gutted all of those scripts and started again and now it seems to work.

I guess there are still a couple of things I want to add, such as "game over" screens depending on if you poison the wrong guard or not (forcing you to use that LOOK command!) but that should be possible.

Thank you sooooooo much! I'm sure this won't be the last time I need help (I'll keep banging my head on the wall until I learn) but at least this part is done.
Metal King Slime
Send private message
 
 PostWed May 22, 2013 12:45 am
Send private message Reply with quote
Great! Wow, you didn't even complain that the scripts above were unreadable because the forum software mangled them :P
Slime Knight
Send private message
 
 PostWed May 22, 2013 5:27 pm
Send private message Reply with quote
UUUUUUUUUGHHHHHHHH.

Why can't this work? I figured adding different outcomes based on which guard would be easy. Here is what I tried:


Code:

     if (check tag(25) && check tag(21)) then (
         reset game   
      )
      else if (check tag(25) && check tag(22)) then(
          reset game   
      )
      else if (check tag(25) && check tag(23)) then (
       # Whatever happens when you poison the well, but not when you leave the map
         create NPC(5, 30, 13, west)
      )


tag 21 is set in the script "brigand" and turned off at the end, tag 22 in "brigand2" etc..

And other than that I realized it doesn't make sense for you to be able to poison the barrel when a guard is walking somewhere unrelated and for him to just drop... I figure I can remove the first few skippable waits so you have to wait until a certain point, but if you miss your window of opportunity I'm not sure how to handle it.

Do I override spacebar somehow? I copied an "onkeypress handler" from an old castleparadox thread that ignores key presses, I suppose I could try using that with a tag.
Metal King Slime
Send private message
 
 PostSat May 25, 2013 12:34 am
Send private message Reply with quote
Back; sorry, had a crunch period for a couple days.

The reason that won't work is that your 3 scripts are called in sequence, and they start and end by setting the right tag. But when the exit condition (skipping waits) is turned on, in order for the scripts to be exited, all three are instantly run through to reach the end of the main while loop. That means all the tags are turned on and back off, regardless of the point at which they were at when "skipping waits" was turned on.

So what you want to do is check tags 21, 22, and 23 at the point that tag 25 and skipping waits are turned on. So in "brigand skip checks", replace the line

Code:

         set tag (25,on)


with

Code:

         set tag (25,on)
         if (check tag(21)) then (
             reset game   
         )
         else if (check tag(22)) then(
             reset game   
         )
         else if (check tag(23)) then (
            # Nothing, let's handle this at the end of calbrigands (but you could do stuff here if you wanted)
         )


And then you can put the createnpc at the end of "callbrigands".

An alternative to be to set a bunch of tags in "brigand skip checks" depending on which tags are set at the point that tag 25 is turned on, and then check those in callbrigands.

You can disable the normal use of space bar using the "suspend player" trick (which is what I think you meant), but that doesn't affect "key is pressed", which is what you are using.
Instead, just set a tag (in brigand 1,2,3) indicating whether or not the barrel is currently usable, and in "brigand skip checks", check the tag. Don't change any "skippable wait"s to regular waits. For example, replace
Code:

      if (key is pressed(key:space) || key is pressed(key:enter) || key is pressed(key:ctrl)) then (
         set tag (25,on)
      )

with

Code:

      if (key is pressed(key:space) || key is pressed(key:enter) || key is pressed(key:ctrl)) then (
         if (check tag(tag:can poison barrel)) then (set tag (25,on))
      )
Slime Knight
Send private message
 
 PostTue May 28, 2013 6:26 pm
Send private message Reply with quote
I'm back! My girlfriend and I got a dog, so finding time to work on my game has been a bit hard.

That successfully solved my problem though, and I believe actually resolves this thread!

I did add in another part, it didn't ACTUALLY make sense for the scripts to end immediately, so with some tag trickery, I made it wait until the guards sat down and took a drink and keeled over until you get a game over (or not.) The fact that I was able to figure out how to do that without asking for help means you've taught me something!

I think perhaps the biggest thing that I've learned from all of this is... even something that seems simple on the surface needs to be approached not only from what you want to do but also what you DON'T want it to do. Not only that, but, is this really what I'm asking the script to do?

Anyways, thanks a lot TMC, and I hope I don't need to post back when I try and give these guys a small field of vision (I probably will!)
Metal King Slime
Send private message
 
 PostWed May 29, 2013 11:58 pm
Send private message Reply with quote
I'm pleased to hear that! A lot of people don't understand scripts they are given and don't seem to learn anything.

To give another viewpoint on what you said, people who are new to scripting/programming often try to program in a declarative way: telling the computer what they want, rather than how to do it (imperative programming). I see lots of people misreading imperative statements (like "if (something) then (exit script)") as being declarative (taking effect throughout the whole script) because it's a natural way to read it.

Declarative programming languages do exist. I plan to add declarative statements to hamsterspeak, for example "exit script on map change" and "whenever (check tag(25) == true) do (exit script)" to make what you wanted to do much easier. Of course having a mix of two styles might be even more confusing.
Display posts from previous:
Page «  1, 2