Skip to main content

News

Topic: Menu tutorial issue (Read 213 times) previous topic - next topic

Menu tutorial issue
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
  • Last Edit: July 31, 2017, 11:44:37 am by Miscreant - TheOne&Only
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Menu tutorial issue
Reply #1
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...
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger
thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

Re: Menu tutorial issue
Reply #2
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.
  • Last Edit: July 31, 2017, 02:22:47 pm by Miscreant
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Rhuan
  • [*][*][*][*]
Re: Menu tutorial issue
Reply #3
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.

Re: Menu tutorial issue
Reply #4
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.
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Menu tutorial issue
Reply #5
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. :)

Re: Menu tutorial issue
Reply #6
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.
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Menu tutorial issue
Reply #7
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. :)

Re: Menu tutorial issue
Reply #8
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.
  • Last Edit: August 01, 2017, 02:11:38 pm by Miscreant
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Menu tutorial issue
Reply #9
You mean miniSphere doesn't function at all for you? That sounds pretty serious, might want to discuss that with @Fat Cerberus.

Re: Menu tutorial issue
Reply #10
It does but it crashes alot. i just saw a post he mentioned me in about it.
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Menu tutorial issue
Reply #11
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?
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger
thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Menu tutorial issue
Reply #12
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.

Re: Menu tutorial issue
Reply #13
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.
  • Last Edit: August 01, 2017, 05:28:22 pm by Miscreant
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Menu tutorial issue
Reply #14
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
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger
thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan