trouble with crafting script

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

trouble with crafting script

Post by marionline »

I am having trouble with my crafting script.

Start script talking to NPC:
Image

See Menu and already a textbox is shown.
Image

Get another Menu with textbox.
Image

I used TMC ideas from here (link:http://www.slimesalad.com/forum/viewtop ... c&start=25)
and Bob's explainations on string sprintf (link:http://www.slimesalad.com/forum/viewtopic.php?t=7142) show to what item was created.
Also, I added a suspend player to prevent the player from running away from the workbench (here it's still just an NPC) while crafting.

It seems that from time to time the menu shows there is already a text box behind it, saysing something was created. I am not 100% sure why or then it is happening. I think it happens the first time the script is run.

Could it be that the carfting script is triggered twice? :???:
Are there some variables messing with eachother? Did I just overlook a bug?
Once again, I'm asking for help. xD

I'll post the whole script here:

Code: Select all

# Thanks to Bob the ­Hamster
#http://www.slimesalad.com/forum/viewtopic.php?t=7142
script, get_item, itemid, begin
    $0="You created SOMETHING COOL." 
    string sprintf(0, $1="You created: %s",  get item name(1, itemid))
    get item (itemid)
    show textbox (230)
    wait for textbox
end    
    
# script made by TCM (http://www.slimesalad.com/forum/viewtopic.php?p=125787#125787)
# name is a string id, whichscript is a script id
script, add craft recipe, name, which script, begin 
  open menu(20)
  variable(mitem)
  mitem := add menu item(top menu)
  set menu item type(mitem, menutype:script)
  set menu item subtype(mitem, which script)
  set menu item caption(mitem, name)
  set menu item bit(mitem, menu item bit:close menu when selected, on)
end

((lot's of recipe go here))

script,craft_charm_dog,begin
    delete item(77)
    delete item(16)
    delete item(43)       
    get_item(95)
end    
    
plotscript, carfting, begin
# TODO: StringNumbers: sort this so player gets a nice list
    
    #QUEST ITEMS
    if (inventory(11) && inventory(79) && inventory(45)) then (add craft recipe($0="Vial of Invisibility", @craft_invisibility_vial))
    # AMULETTS
    if (inventory (57) && inventory (28) && inventory(42)) then (add craft recipe($1="Amulett of Fire", @craft_amulett_of_fire)) 
    if (inventory (28) && inventory (42) && inventory(65)) then (add craft recipe($2="Amulett of Ice", @craft_amulett_of_ice)) 
    if (inventory (item:Stone) && inventory (item:Thread) && inventory(46)) then (add craft recipe($3="Amulett of Air", @craft_amulett_of_air)) 
    if (inventory (69) && inventory(90) && inventory(42)) then (add craft recipe($4="Amulett of Light", @craft_amulett_of_light))
    if (inventory(54) && inventory(90) && inventory(42)) then (add craft recipe($5="Amulett of Darkness", @craft_amulett_of_darkness))  
    if (inventory(66) && inventory(90) && inventory(42)) then (add craft recipe($6="Amulett of Illusion", @craft_amulett_of_illusion))
    if (inventory (78) && inventory (42) && inventory(103) && inventory(60)) then (add craft recipe($7="Amulett of Water", @craft_amulett_of_water)) 
    if (inventory (56) && inventory (78) && inventory(42) && inventory(60)) then (add craft recipe($8="Amulett of Earth", @craft_amulett_of_earth)) 
    if (inventory (42) && inventory(78) && inventory(80) && inventory(60)) then (add craft recipe($9="Amulett of Plants", @craft_amulett_of_plants)) 
    if (inventory (78) && inventory (89) && inventory(42)) then (add craft recipe($10="Amulett of Regeneration", @craft_amulett_of_regeneration)) 

   
    # POTIONS
    if (inventory(69) && inventory (44) && inventory (67)) then (add craft recipe($11="Potion (500)", @craft_potion500))
    if (inventory(16) && inventory (112) && inventory (69)) then ( add craft recipe($12="Potion (200)", @craft_potion200))
    if (inventory(111) && inventory(69) && inventory(31)) then ( add craft recipe($13="Potion (100)", @craft_potion100))
    if (inventory(69) && inventory (43) && inventory (111)) then ( add craft recipe($14="Potion (50)", @craft_potion50))
    if (inventory(69) && inventory (91) && inventory (43)) then (add craft recipe($15="Potion (20)", @craft_potion20))
    
    # MP POTION    
    if (inventory(91) && inventory (43)) then (add craft recipe($16="MedMP (10)", @craft_MP_potion10))
    if (inventory(43) && inventory (111)) then (add craft recipe($17="MedMP (15)", @craft_MP_potion15))
    if (inventory(43) && inventory (111) && inventory(31)) then (add craft recipe($18="MedMP (25)", @craft_MP_potion25))
    if (inventory(43) && inventory (91) && inventory(111) && inventory(31)) then (add craft recipe($19="MedMP (50)", @craft_MP_potion50))
    if (inventory(44) && inventory (41)) then (add craft recipe($20="MedMP (100)", @craft_MP_potion100))
    
    # Medecine: 
    if (inventory(43) && inventory (51)) then (add craft recipe($21="Medicine (Poision) (100)", @craft_Med_P))
    if (inventory(51) && inventory (64) && inventory(91)) then (add craft recipe($22="Medicine (Stun)", @craft_Med_S))
    if (inventory(64) && inventory (91) && inventory(43) && inventory (112)) then (add craft recipe($23="Medicine(Mute)", @craft_Med_M))

    #SCROLLS
    if (inventory(102) && inventory(60)) then (add craft recipe($24="Glue Scroll",@craft_glue_scroll))
    if (inventory(55) && inventory(91) && inventory(16) && inventory(102)) then (add craft recipe($25="Rage Scroll",@craft_rage_scroll))
    if (inventory(114) && inventory(102) && inventory(55)) then (add craft recipe($26="Poision Scroll",@craft_poision_scroll))
    if (inventory(91) && inventory(16) && inventory(102)) then (add craft recipe($27="Stun Scroll",@craft_stun_scroll))
    if(inventory(66) && inventory(16) && inventory(102))  then (add craft recipe($28="Mute Stun",@craft_mute_scroll))
    if (inventory(16) && inventory(102) && inventory(89)) then (add craft recipe($29="Regeneration Scroll",@craft_regeneration_scroll))
    if (inventory(52) && inventory(57) && inventory(102)) then (add craft recipe($30="'Heat-Scroll",@craft_heat_scroll))
    if (inventory(52) && inventory(102) && inventory(65)) then (add craft recipe($31="Cool-Scroll",@craft_cool_scroll))
    if (inventory(52) && inventory(102) && inventory(69)) then (add craft recipe($32="Scroll of Light",@craft_light_scroll))
    if (inventory(46) && inventory(16) && inventory(102) && inventory(46)) then (add craft recipe($33="Scroll of Noise",@craft_noise_scroll))
    if (inventory(52) && inventory(54) && inventory(102) && inventory(45)) then (add craft recipe($34="Absorb Scroll",@craft_absorb_scroll)) 
    if (inventory(102) && inventory(55) && inventory(16) &&  inventory(56)) then (add craft recipe($35="Scroll of Dust", @craft_dust_scroll)) 
    if (inventory(56) && inventory(91) && inventory(45) &&  inventory(91)) then (add craft recipe($36="Scroll of Gardening", @craft_gardening_scroll)) 
    if (inventory(111) && inventory(31) && inventory(45) && inventory(102)) then (add craft recipe($37="Flower Spell Scroll", @craft_flower_scroll)) 
    if (inventory(57) && inventory(102) && inventory(31)) then (add craft recipe($38="Campfire Spell Scroll", @craft_campfire_scroll)) 
    
    #CHARMS
    if (inventory(77) && inventory(16) && inventory(42)) then (add craft recipe($39="Charm of Defense", @craft_charm_def)) 
    if (inventory(77) && inventory(16) && inventory(43)) then (add craft recipe($40="Charm of Dodge", craft_charm_dog))
    if (inventory(77) && inventory(16) && inventory(104)) then (add craft recipe($41="Charm of Attk", craft_charm_attk))  
    if (inventory(77) && inventory(45) && inventory(16)) then (add craft recipe($42="Charm of Aim", @craft_charm_aim)) 
    if (inventory(77) && inventory(16) && inventory(83)) then (add craft recipe($43="Charm of Health", @craft_charm_hp)) 
    if (inventory(54) && inventory(77) && inventory(16)) then (add craft recipe($44="Charm of Confidence", @craft_charm_conf)) 
    if (inventory(16) && inventory(66) && inventory(77) && inventory(45)) then (add craft recipe($45="Charm of Magic", @craft_charm_mag))
    if (inventory(52) && inventory(77) && inventory(31) && inventory (16)) then (add craft recipe($46="Charm of MagicPower", @craft_charm_mp)) 
    if (inventory(44) && inventory(31) && inventory(77) && inventory(110)) then (add craft recipe($47="Lucky Charm", @craft_charm_luc)) 
    
    # RESSOURCES
    if (inventory(77) && inventory(104) && inventory (60)) then (add craft recipe($48="empty Scroll",@craft_empty_scroll))
    if (inventory(111) && inventory(55) && inventory (43)) then (add craft recipe($49="Ink",@craft_ink))
    if (inventory(24) > 3) then (add craft recipe($50="Glue",@craft_glue))
    if (inventory(79) && inventory(43)) then (add craft recipe($51="Poision",@craft_poision))
    if (inventory (79) && inventory (24) && inventory(111) && inventory(45)) then (add craft recipe($52="RegenerationFluid", @craft_regeneration_fluid)) 
    
    #TOOLS/ITEMS
    if (inventory(104) && inventory(28) && inventory(42)) then (add craft recipe($53="SlingShot", @craft_slingshot))
    
    #ADD LATER
    #if (inventory(104) && inventory(16) && inventory (item:46)) then (add craft recipe($51="Speed-Up-Spell",@craft_speed_up))
    #if (inventory(101) && inventory(16) && inventory (item:56)) then (add craft recipe($52="Slow-Down-Speed",@craft_speed_down))
end
Last edited by marionline on Thu Dec 01, 2016 6:45 pm, edited 1 time in total.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

(Sorry for the slow response; I've been in Mexico for nearly 2 weeks.)

I'm not sure why this is happening. Maybe it's because you held down the use key, and something from the menu is selected as soon as it's opened, and then it's reopened again immediately? I think if that happens, you won't even see the menu disappear for a brief moment, so you won't know that you closed it and immediately reopened it. See if holding down the use key causes the problem.
A wait command at the beginning of the "crafting" script might be enough to stop that happening.

"open menu(20)" was actually meant to go at the beginning of the "crafting" script, not the "add craft recipe" script, but it turns out that it makes no difference, because by default the menu isn't opened again if it's already open.

Also:
-"amulett" should be spelt "amulet"
-You don't have to use a different string id number for each recipe. They can all use string 0 (like $0="Speed-Up-Spell").
-It looks like your menu 20 starts with one blank menu item, but if it doesn't have any purpose then you can just delete it in the menu editor.
Last edited by TMC on Mon Dec 12, 2016 9:37 am, edited 2 times in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Hello TMC,
thanks for you help. :D

I used the advices you gave, and I found the bugs.
There were '@'s missing in the crafting scripts for Charm attk and charm dog. Without the '@' the script seems to be executed immediately. That's why these messages were displayed. Also an surplus open menu function (I might have added when trying to find the bug) caused side effects, so to say.

But now the script runs fine. :)
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Ah, great!
When you make a typo when writing code anything could happen; the only way to figure it out is to figure out what the code is doing, e.g. where the "craft_charm_dog" script was actually getting called from.
Post Reply