Need to have a menu item run a script and display text

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

Moderators: marionline, SDHawk

Post Reply
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Need to have a menu item run a script and display text

Post by Foxley »

I'm making a bestiary menu for my game with enemy info, here's a quick mockup I did to test the script.
Image


However in order to have the text box show immediately instead of after the main menu closes, I had to enable the "Allow gameplay & scripts" bitset which allows for NPCs and other scripts to continue running. Thing is, this isn't normal menu behavior and I'd really like to not have to do that. And what I need to do is run a script based off of the selected menu item's extra data to put some string sprintf stuff together, before then displaying a text box. So I can't just display a text box and still have the data ready to show.

Any suggestions on how to get around this? Also, ideally I'd like to have a two part menu where one menu is where the player selects a monster's name, and a separate box instantly updates with the enemy info when another enemy is selected. Is there any way to do this with menus, or would it need to be built from scratch?
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

You definitely need to enable "Allow Gameplay And Scripts". You can get the behavior you want by calling "suspend player" and "suspend NPCs" when you open the menu, and then "resume player" and "resume NPCs" when the menu closes
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

It's unavoidable that you need to use a script to update the display, so you need the "Allow gameplay & scripts" bitset. Then suspend everything else: the player, NPCs, timers.
Unfortunately there's no command to stop NPCs/heroes in midstep. Tihis certainly isn't the first time I've seen the need for a "suspend walkabouts" (or "suspend movement"?) command. Hmm, a "suspend tile animation" command would be good too.

If you want the info to update immediately, then you should use a text slice instead of a textbox, because the textbox rolls in a line at a time, and the embed codes are expanded when the textbox is opened, not every tick after that. Actually, both are things I really want to change... Oh great. Now I've started working on it.

Anyway, to make the textbox/text slice update continuously is straightforward:

Code: Select all

plotscript, bestiary, begin
  variable(extra)
  while (top menu) do (  # While a menu is open
    extra := get menu item extra(selected menu item, 0)
    # Update the display...
    wait(1)
  )
end
Post Reply