New to OHRRPGCE - Need help with plotscripting

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

New to OHRRPGCE - Need help with plotscripting

Post by crowtongue »

Hi there,

I've just recently started using OHRRPGCE and so far am enjoying it quite a bit. I find it pretty easy to use generally, except that learning plotscripting is basically just randomly traversing through these forums, which are terrible to search (am I just missing how to search for exact strings?)

Anyhow, here's what I'm working on at the moment.

My towns are a backdrop image with a combination of smaller maps to walk around for some buildings, and menus for others. Initially you are just presented with a menu that is a list of locations.

Chapel
Tavern
Market

etc... I am trying to script a system so that whatever menu item is currently selected displays the relevant textbox for each option.

Here is my code to start:

Code: Select all

plotscript, firsttown, begin
	suspend player
	show backdrop(0)
	open menu(1, false)
	if (selected menu item == 0) then (
		 show text box(1)
		)
	resume player
This shows the backdrop and menu, but does not show my text box when the first menu item is selected. It's likely that I'm missing the proper usage for menu item handles, but I can't find more about this in the dictionary. Can anyone help?

Bonus points! - I want to present a static yes - no option for each text box that can be selected with the left and right arrow keys. Is this possible without creating another menu or textbox?
User avatar
BMR
Metal King Slime
Posts: 3310
Joined: Mon Feb 27, 2012 2:46 pm
Location: The Philippines
Contact:

Post by BMR »

I might be mistaken, but I think you need a "wait for text box" after calling the textbox. Alternatively, you could mess around with text slices, but that might be a bit much. Heh, even I still have trouble with them at times.
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

Post by crowtongue »

I added a wait for text box, and it didn't change anything.

Not sure about text slices at this point, I'd rather just learn how to get it working how I've already started. Thanks though!
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Hi, welcome!

Firstly, yeah, I'd like to see a much more comprehensive list of example scripts on the wiki. Lots of useful scripts get posted to the forums and then forgotten because of the extra work that creating an article is. "Read through the plotscripting dictionary" is no longer as good advice as it used to be, as there are a huge number of commands now. And I think the dictionary really needs sections explaining topics like menu item handles, NPC references, the party order, etc. Hmm, I see that the documentation for the menu commands is particularly lacking in details...

If you want to search these forums (and also of course castleparadox.com, which has a decade of useful material) do a Google search prefixed with "site:slimesalad.com"

Now, menu item handles. A menu item handle is a meaningless number that refers to a specific item in a specific menu. To convert it to the slot number in the menu you want menu item true slot ("menu item slot" gives you a slot number that depends on which items are visible due to tags, so often best to avoid).

You also want a while loop to continually update to the right textbox. But you don't want to call 'show textbox' every tick either! See the script.

And make sure that the "Allow gameplay & scripts" menu bit is on for menu 1, otherwise the script will pause until the menu is gone.

Finally be warned that interaction between textboxes and menus is a bit odd in places; there are unfixed bugs and missing features around this. If you have a textbox and a menu open at once, pressing enter will close the textbox, and pressing Esc closes the menu. So I had to add some more complication to the script for this. It probably still won't work right in all circumstances, so just ask! What you are asking for is unforunately much more complicated than it should be.

Code: Select all

plotscript, first town, begin
   suspend player
   suspend box advance # prevent the player from closing the text boxes
   show backdrop(0) 
   variable (menu, prev slot, slot)
   menu := open menu(1, false)
   prev slot := -1
   while (menu is open(menu)) do (
      if (top menu == menu) then (
         # Future proofing: if another menu is openned on top of this one, the script stops updating
         slot := menu item true slot (selected menu item)
         if &#40;slot <> prev slot&#41; then &#40;
            # Continually calling 'show text box' will prevent the line-by-line display of the textbox from ever finishing
            if &#40;slot == 0&#41; then &#40; 
               show text box&#40;1&#41; 
            &#41; else &#40;if &#40;slot == 1&#41; then &#40;  # After Beelzebufo is released, you can use 'else if' instead
               show text box&#40;2&#41; 
            &#41; else &#40;if &#40;slot == 2&#41; then &#40; 
               show text box&#40;3&#41; 
            &#41;&#41;&#41;
         &#41;
         prev slot &#58;= slot
      &#41;
      wait
   &#41;
   # If the player presses Esc to close the menu, close the box too
   advance text box
   resume player
   resume box advance
end
As for the yes-no option: well, that's difficult. You can't use textbox choice boxes, because you can't control them with scripts in order to make the left+right keys control them. But you can't use two menus open at once either, because only one menu at a time is active, and the others don't highlight their current selection. So either you could show the yes/no prompt after you press Enter, or you need to script something with slices.
Last edited by TMC on Sat Mar 23, 2013 8:59 am, edited 1 time in total.
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

Post by crowtongue »

I'm not sure why it didn't occur to me to just search on Google, but that's great, that will help me a lot.

Rereading my initial post I hope it didn't come across too negative. It seems like a fairly labyrinthine process finding out certain things... but this program is also 15 years old at the very least, and it seems to have a very helpful community around it.
Now, menu item handles. A menu item handle is a meaningless number that refers to a specific item in a specific menu. To convert it to the slot number in the menu you want menu item true slot ("menu item slot" gives you a slot number that depends on which items are visible due to tags, so often best to avoid).
I must have somehow glazed over this part in the dictionary, but this is extremely helpful to know. Thanks!
And make sure that the "Allow gameplay & scripts" menu bit is on for menu 1, otherwise the script will pause until the menu is gone.
I don't think I would have found this out on my own!

As for the yes-no option: well, that's difficult. You can't use textbox choice boxes, because you can't control them with scripts in order to make the left+right keys control them. But you can't use two menus open at once either, because only one menu at a time is active, and the others don't highlight their current selection. So either you could show the yes/no prompt after you press Enter, or you need to script something with slices.
I think you hit the nail on the head. I will use enter to make the selection, then use a choice box after that to determine whether the player moves on or goes back to the initial menu. That works well enough for my purposes.

I haven't typed this up into my script yet, but I'll report back later if I have any problems. Thanks again.
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

Post by crowtongue »

Ok so this script works decently so far, except that I now see the limitations of text boxes. I don't see any way for example to position it on the screen and change the width of it. What I'm going for is a box on the right side of the screen that takes up about a third of the screen width-wise, only. It has a portrait inside of it, a title, and a description.

I'm thinking that I need to use "create rect" instead of text boxes (unless there is a way to change these things that I can't find.) I just want to make sure that I'm on the right track and these things can be done.
User avatar
shakeyair
Slime Knight
Posts: 217
Joined: Fri Jun 12, 2009 6:15 am

Post by shakeyair »

You are correct, but instead of loading all those slices by hand, just make a Slice Collection in Custom, then load that. Easier to lay out that way.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

And in case you haven't seen it, there is a tutorial for slices on the wiki.
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

Post by crowtongue »

So I read that tutorial, and created a slice collection. This seems like it should work easier, except that it somehow doesn't.

Code: Select all

  while &#40;menu is open&#40;menu&#41;&#41; do &#40; 
      if &#40;top menu == menu&#41; then &#40; 
         # Future proofing&#58; if another menu is openned on top of this one, the script stops updating 
         slot &#58;= menu item true slot &#40;selected menu item&#41; 
         if &#40;slot <> prev slot&#41; then &#40; 
            # Continually calling 'show text box' will prevent the line-by-line display of the textbox from ever finishing 
            if &#40;slot == 0&#41; then &#40; 
                variable&#40;sl&#41;
                    sl &#58;= load slice collection&#40;1&#41;
            &#41;&#41;&#41; 
According to the tutorial, the plotscripting dictionary, and an example file I looked up this should work, but it doesn't display anything. Any ideas?
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I think you misunderstood why I put three brackets there That was to close off the three nested "else" statements. You've removed the rest of the loop, including the wait command, which was crucial. I guess I should have indented properly. But in fact there was no need for me to use nested elses at all; you can just put multiple if statements one after the other.

Modifying the script I posted is simple, and you were nearly there; you need to add "free slice" to remove the old collection too:

Code: Select all

plotscript, first town, begin 
   suspend player 
   show backdrop&#40;0&#41; 
   variable &#40;menu, prev slot, slot, sl&#41;
   menu &#58;= open menu&#40;1, false&#41; 
   prev slot &#58;= -1 
   while &#40;menu is open&#40;menu&#41;&#41; do &#40; 
      if &#40;top menu == menu&#41; then &#40; 
         # Future proofing&#58; if another menu is openned on top of this one, the script stops updating 
         slot &#58;= menu item true slot &#40;selected menu item&#41; 
         if &#40;slot <> prev slot&#41; then &#40; 
            if &#40;sl&#41; then &#40;
               # Close the old info page
               free slice &#40;sl&#41;
               sl &#58;= 0  # Zeroing out a variable like this is a good idea
            &#41;
            if &#40;slot == 0&#41; then &#40;
               sl &#58;= load slice collection&#40;1&#41;
            &#41;
            # And so on
            #if &#40;slot == 1&#41; then &#40;
            #   sl &#58;= load slice collection&#40;2&#41;
            #&#41;
         &#41; 
         prev slot &#58;= slot 
      &#41; 
      wait 
   &#41; 
   free slice &#40;sl&#41;
   resume player 
   resume box advance 
end
Last edited by TMC on Sun Mar 24, 2013 10:07 am, edited 2 times in total.
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

Post by crowtongue »

I hadn't actually copy pasted my code (I know, I know I really should) I just edited the one you put in this thread and took out the extra choices for brevity (one is enough to see the code I was using) and forgot to take out the brackets. My bad.

Anyways, this is getting a bit frustrating. I've gone through my code and made sure it is identical to yours, but it does nothing. I know it is running because I changed the slice collection to one that doesn't exist and it gives me an error when I run it.

But on the menu it does nothing. I've included my script file and rpg file on dropbox. Please excuse the fact that the graphics are ugly and completely black and white. I'll probably change it all when I have a game worth playing.

To get to the town menu just walk up to the path and all the way to the right.

https://dl.dropbox.com/u/69407974/monochrome.hss
https://dl.dropbox.com/u/69407974/monochrome.rpg
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I like your graphics actually; the town looks very nice!

Heh, you forgot to turn on the "Allow gameplay and scripts" bitset. This bitset is by far the most annoying and troublesome feature of customisable menus.

I did notice I made a mistake in the script: the last "free slice (sl)" should be "if (sl) then (freeslice (sl))", though this only matters if there is a menu item without an assigned slice collection.

I also noticed you set the cancel button to "switch to menu 1" in the menu editor. If you press Esc/Alt, the menu closes, causing the script to end, and then it opens a new menu. You don't want this; turn on the "Disable cancel button" menu bitset instead.
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

Post by crowtongue »

Thank you! I did spend a little more time on the town, which was kind of fun.

So I enabled that bitset, and also added in the "if (sl) then (freeslice (sl))" part since I only have one slice collection, but still nothing. I've taken a look through the dictionary again but can't seem to wrap my head around why nothing is showing on the screen.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Oh! I see what's going on. You're using Alectormancy, but there are improvements to the way that things are drawn to the screen in the latest version. It turns out that in Alectormancy if you show a backdrop nearly nothing else except textboxes and menus are displayed. I hadn't even realised that this limitation had existed. To get around it, just download the Beelzebufo release candidate (aka a nightly build) or wait a couple days for the official release if you want.
Last edited by TMC on Mon Mar 25, 2013 1:16 am, edited 1 time in total.
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

Post by crowtongue »

Well that does it. I downloaded the latest release and now it works. Thanks so much for walking me through this!

There's a bunch of changes I'm going to make implementing some other systems (relatively simple stuff though, I'm pretty confident it can all be done) so I'm sure I'll be back...
Post Reply