Spherical forums

Sphere Development => Sphere Support => Script Support => Topic started by: Miscreant on July 31, 2017, 11:40:45 am

Title: Menu tutorial issue
Post by: Miscreant on July 31, 2017, 11:40:45 am
I followed the tutorial for creating a menu from http://wiki.spheredev.org/Making_a_Menu

As you can see from the code, I followed the "Advanced" methods. However, every time i try to run the sample program i receive the Error "font is not defined." I have included the js files with the code. Might someone be able to look them over and see if I have an error somewhere that would cause this message to appear.

TIA,
Miscreant
-The One and Only
 Accept no imitations
Title: Re: Menu tutorial issue
Post by: Fat Cerberus on July 31, 2017, 12:13:29 pm
font.getHeight() should be this.font.getHeightfont is not a variable, it's a member of the Menu class.

As an aside, that is quite an ancient tutorial and uses the very old and outdated legacy Sphere v1 API.  We really need to get started on making some Sphere v2 tutorials...
Title: Re: Menu tutorial issue
Post by: Miscreant on July 31, 2017, 12:31:55 pm
Thank you. However, the menu is not displaying the menu items. All other aspects of the menu are functioning properly. The attached image shows the output being generated.
Title: Re: Menu tutorial issue
Post by: Rhuan on July 31, 2017, 06:16:11 pm
Thank you. However, the menu is not displaying the menu items. All other aspects of the menu are functioning properly. The attached image shows the output being generated.
Line 44 of menu.js:
this.font.drawText(x+16, y + i * font_height, this.items[i+offset]);
Should instead be:
this.font.drawText(x+16, y + i * font_height, this.items[i+offset].name);

Each menu item has multiple properties you were referencing the item for the text to draw when you instead need to reference the property you want drawn (the name or the description, I've assumed the name)

As an aside, that is quite an ancient tutorial and uses the very old and outdated legacy Sphere v1 API.  We really need to get started on making some Sphere v2 tutorials...
To be honest I don't think we're quite there yet with Sphere v2, we nearly are, let me get the mape system I've been working on ready (hopefully early september) then let's do a bit more testing and then I think it will be time to really push v2.
Title: Re: Menu tutorial issue
Post by: Miscreant on July 31, 2017, 06:29:12 pm
Thank you Rhuan. It's always good to have a second set of eyes when trying to debug an error. I have one guy, we've been debugging each others programs since college but when it comes to JS he's in the dark.
Title: Re: Menu tutorial issue
Post by: DaVince on August 01, 2017, 09:32:29 am
Apparently I wrote this tutorial a long time ago and completely forgot about it. I'm kinda surprised I never tested my own code. Sorry about that. As shown in Menu.prototype.addItem, items are created with several properties indeed, so in order to get the name to appear you'd have to refer to the name property, as mentioned.

The desc property is entirely separate so you can give items neat descriptions and display those next to the menu or whatever, by the way. :)
Title: Re: Menu tutorial issue
Post by: Miscreant on August 01, 2017, 11:30:54 am
I'm kinda surprised I never tested my own code. Sorry about that.

It happens. I've done it myself on other platforms.

I have been reading through your scripting tutorial. It has been very helpful. It answered a perplexing problem I was encountering with a character object I was pseudocoding for later use. I've been developing an rpg in parts since '98. Mostly on paper and text files. Sphere is letting that idea take form.
Title: Re: Menu tutorial issue
Post by: DaVince on August 01, 2017, 01:45:15 pm
I'm glad it's been helpful! By now it's entirely geared towards the old API as opposed to the whole shiny new one, but it'll be just as helpful when you just want to make your game, I suppose.

Also make sure to keep an eye on Legacy:Functions (http://wiki.spheredev.org/Legacy:Functions). :)
Title: Re: Menu tutorial issue
Post by: Miscreant on August 01, 2017, 02:08:56 pm
By now it's entirely geared towards the old API as opposed to the whole shiny new one

I have been unable to get any of the other forms of Sphere to function correctly on my development machine(DM) so I have been currently using Sphere 1.5. I figure it is a good way to start out with JS (not for webpage development). Figure if I can understand and build code in the original environment, I can take that knowledge over to the update versions when i figure out how to get them to function on my DM.

Also, I reference api.txt in the Sphere Docs folder alot.
Title: Re: Menu tutorial issue
Post by: DaVince on August 01, 2017, 02:11:40 pm
You mean miniSphere doesn't function at all for you? That sounds pretty serious, might want to discuss that with @Fat Cerberus.
Title: Re: Menu tutorial issue
Post by: Miscreant on August 01, 2017, 02:13:37 pm
It does but it crashes alot. i just saw a post he mentioned me in about it.
Title: Re: Menu tutorial issue
Post by: Fat Cerberus on August 01, 2017, 02:20:56 pm
It does but it crashes alot. i just saw a post he mentioned me in about it.

Sphere Studio is currently a bit buggy and does tend to crash in spots.  I'm working on making it more stable as we speak.  But miniSphere has been rock-solid stable for pretty much everyone I've talked to that's used it.  Where are you getting crashes exactly?
Title: Re: Menu tutorial issue
Post by: DaVince on August 01, 2017, 04:10:11 pm
Oh, that's right - the Sphere Studio IDE might be unstable, but nothing is stopping you from using the old Sphere editor with the new miniSphere engine if you wish to do that. (Heck, that's what I do since Sphere Studio doesn't run well under Linux!)

And truly, using miniSphere IS much recommended, I would say.
Title: Re: Menu tutorial issue
Post by: Miscreant on August 01, 2017, 05:09:52 pm
miniSphere does function. However, here is one interesting issue. While testing miniSphere it just gave me an error while trying to load a map i have not created yet. That is not the issue. The issue is "[Space]/[Esc] to close..." it is not exiting, the screen is full screen and i had to use windows task manager to close it.
Title: Re: Menu tutorial issue
Post by: Fat Cerberus on August 01, 2017, 05:57:02 pm
Huh, that's strange.  You're the first person who's ever had that issue.  I'll look into it, though and if something's broken you can be sure I'll have it fixed in short order. :D
Title: Re: Menu tutorial issue
Post by: Miscreant on August 03, 2017, 06:12:30 pm
one more question about this menu

I have been trying to use BindKey(KEY_TILDE, "", "");
to access the menu. I have tried a few different methods but with no real success. I have used BindKey for other functions such as
DebugXY: returns the players current x,y values
DebugLayer: returns what layer the player is currently on (found very useful when i was creating my raft function and the player suddenly stopped moving)
DebugPlayer: which returns the variables for the player. hp, items, currency etc...

all of which function the way they are designed to. However, attempting to bindkey this menu is not functioning. Any suggestions?
Title: Re: Menu tutorial issue
Post by: Rhuan on August 03, 2017, 08:51:30 pm
From a quick glance back at your code I can't see a function you could call to run that menu, it's the second half of your game function after the MapEngine() call which means the code won't be evaluated until the MapEngine has ended.

You need to break the menu out into its own function:
Code: [Select]
function gameMenu()
{
  var myMenu = new Menu();
  myMenu.addItem("Item 1", "Item 1", Exit);
  myMenu.addItem("Item 2", "Item 2", Exit);
  myMenu.addItem("Item 3", "Item 3", Exit);

  myMenu.preRender = function()
  {
    if (IsMapEngineRunning())
    {
      RenderMap();
      UpdateMapEngine();
    }
  }

  myMenu.execute(GetScreenWidth()/2-80, GetScreenHeight()/-40,160,80);
}

Then BindKey(KEY_TILDE, gameMenu, ""); should work. Note the above function will need to be defined globally (i.e. not inside the game function) in order to be reachable by the mapengine.
Title: Re: Menu tutorial issue
Post by: Miscreant on August 03, 2017, 09:00:11 pm
You need to break the menu out into its own function

I'll give that a try. I appreciate the feedback.