Post new topic    
Page «  1, 2, 3
Metal King Slime
Send private message
 
 PostThu Nov 27, 2014 8:57 am
Send private message Reply with quote
I warned you that you must not call "destroy npc (npc at spot(hero x, hero y))" without checking that the npc actually exists, otherwise it will delete some copy of NPC 0. I think that's what's happening here.You can delete all the "surplus" NPCs on the map; create NPC definitely doesn't move existing NPCs.

It would be best if the script just continued if the recipe is invalid. Calling the script again, as you tried could have worked, but probably didn't because you didn't include a wait, so the script immediately tests the recipe again because it sees Enter is still down, calls itself again, etc, getting into an infinite loop that's stopped by the engine. However just adding a wait isn't great, because holding down Enter will still cause it to loop, and if it repeats too many times (128) the script interpreter will stop the script. You could hit that if you make a number of wrong guesses, but adding a longer wait (e.g "wait(6)") would make it pretty unlikely. The best solution would be move everything into a "while(true) do(...)" loop, and "exit script" when the player tries to quit or gets a recipe right, but it's not strictly necessary.

Anyway, even if you resume the script after a wrong recipe you're still going to need to iterate over the NPCs and return all items to the inventory if the player wants to leave the crafting board. I suggest having a single script to check for an NPC somewhere, and delete it if it exists. Like your "deletion" script, but taking x and y as arguments:

Code:
script, delete from board, x, y, begin
  variable(npcref, id)
  npcref := npc at spot(x, y)   # get the NPC reference
  id := npc id at spot(x, y)
  if (npcref == 0) then (exit script)
  destroy npc (npcref)

  # Figure out which item to return
  if (id == 0) then (get item (item: iron))
  else if (id == 1) then (get item (item: wood))
  #  ... etc
end


Now you can use this script everywhere. When you add a new placeable item you don't want to have to update multiple scripts everywhere.

Now you can use this to delete every item on the board. Lets set the board is from x = 4 to 7 (inclusive) and y = 2 to 5. Just use two loops to delete every item:
Code:

variable (x, y)
for (x, 4, 8) do (
  for (y, 2, 5) do (
    delete from board(x, y)
  )
)

I hope these scripts are self explanatory and also show you how to use for loops and how to split things into multiple scripts (I'm expecting you to learn from this!)

However if you wanted you could iterate over all the npcs on the map, using "npc reference" and "npc copy count" commands, and delete them that way. I'm just suggesting that if you do that, that you can make your scripts a lot cleaner and shorter by having a single script to delete an npc and return the corresponding item to the inventory.
Slime Knight
Send private message
 
 PostThu Nov 27, 2014 9:16 pm
Send private message Reply with quote
UrkTMC.png
Hahaha, I am learning, really, I swear I am!

It is now so very close to working perfectly. I used the scripts you posted, and have implemented them in my crafting script as a Reset-Table type of command.

Following my current list of crafting recipes used to check the board for correctly crafted items, I have a final Else command, which calls the reset-table script, returning the appropriate items in the correct quantities to the player's inventory. This is working perfectly for incorrectly crafted items.

However, when I have that reset-table script as the final "else" in the list of crafting recipes, pressing enter with a correctly implemented recipe still calls the reset-table script. making it impossible to receive the item. I took a little time away, and am about to go back and start troubleshooting again.

But thank you once again, as those tiny little scripts you provided allowed me to deal with what could have been quite an inconvenience.

To show my appreciation for all the help you've given me, I have illustrated a picture based upon your life in this past week or so:
Metal King Slime
Send private message
 
 PostFri Nov 28, 2014 8:37 am
Send private message Reply with quote
Hahah, I appreciate that picture!

If the board gets reset regardless of whether the recipe is correct does that mean that the reset isn't actually inside the 'else' block?
Slime Knight
Send private message
 
 PostMon Dec 01, 2014 3:49 pm
Send private message Reply with quote
Alright, I think that I've finally got everything in pretty good order. I have a few text files with scripts, and a little example game that I'd like to put up for folks to try out, edit, expand upon, complain about, ect.. They are contained in a .Rar file

Is this something that would be possible/appropriate to post somewhere on the forums, or should I find a place to upload it, and just leave a link in this thread?
Metal King Slime
Send private message
 
 PostMon Dec 01, 2014 3:59 pm
Send private message Reply with quote
The gamelist is fine for uploading examples and tech demos. You could even upload that sort of thing to the OHR wiki.
Slime Knight
Send private message
 
 PostMon Dec 01, 2014 7:42 pm
Send private message Reply with quote
Rad, thanks much!
Metal King Slime
Send private message
 
 PostFri Dec 05, 2014 1:03 pm
Send private message Reply with quote
Because you've kindly provided all scripts and everything I made some improvements to the scripts.

This:
Code:
else (resettable), (wait (4)), (crafting)

Isn't right. You can only put one "block" of code in an else, surrounded by ( and ) or begin and end. The "resettable" is in the else block and everything else isn't. This is equivalent to:
Code:
else (resettable)

wait (4)
crafting

What you probably wanted to write was:
Code:
else (resettable, wait (4), crafting)

There were also some other crazy things, like putting a "show textbox(11)" in the middle of the "for" loops in "reset table". After or before the loop is the reasonable place to put it. (But I moved that showtextbox elsewhere, so that I could call "reset table" without showing the textbox.)

In the end there were too many bugfixes and changes for me to list. Instead, here is a diff, which you might be able to make sense of:
http://pastebin.com/1rXxgqaB
And here is the final script file:
http://pastebin.com/BFxcuNUc
(Sadly SS doesn't allow .txt files as attachments) Hopefully if you've edited the scripts yourself since you can look at the diff to figure out what I changed.

In addition to changing the scripts I had to make one change to the .rpg file. I modified textbox 18 so that instead of using door 2 it runs the script "leave table" afterwards.

Notice that I made the recipes much more pretty. Also I changed the behaviour so that on a wrong recipe it doesn't reset the table, but you can change that easily (I left a comment).
Slime Knight
Send private message
 
 PostFri Dec 05, 2014 3:11 pm
Send private message Reply with quote
Awesome Smile
I was hoping that including all the scripts would help/encourage folks to edit, and improve the system.

Also, thanks for prettying up the code, and streamlining it. I tried to format it, and remove the free-floating strings, textboxes, and scripts, but I knew there would still be some in there. You should have seen the script file before! You would have throttled me Hurr

Code:
variable(_, W, G, I)
_ := -1  # empty space
W := 0   # wood
I := 1   # iron
G := 2   # gold

^ that blew my mind, haha XD

So again, thanks for all the help (practically doing everything but driving to my house and typing the code for me) knowledge, and patience throughout this endeavor. I'm glad it has resulted in something that may hopefully benefit some folks around here.
Display posts from previous:
Page «  1, 2, 3