Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
gothboy 101
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Watonga, ok, usa
Posted: 4th Aug 2004 01:39
when i click quit its supposed to quit when i click items its supposed to print the text item quanity when i click save and character its supposed to just be a blank box...whats wrong please help me.

data "items",0
data "save",0
data "character",0
data "quit"
if "quit" then end
`Number of submenus
numSubMenus=5

`Where the sub menu names will be stored
dim mainMenu$(numSubMenus)
`Where the item names will be stored
dim subMenu$(numSubMenus,20)
`Where the amount of item will be stored
dim subMenuQuantity(numSubMenus,20)
`Where the amount of items in the sub menu will be stored
dim subMenuAmount(numSubMenus)

`Read in data
for x=1 to numSubMenus
read mainMenu$(x)
read subMenuAmount(x)
for y=1 to subMenuAmount(x)
read subMenu$(x,y)
subMenuQuantity(x,y)=rnd(10)+1
next y
next x

sync on

do
`Background
ink rgb(255,255,255),0
box 0,0,639,479

`Do left menu graphics
ink rgb(100,100,100),0
box 23,23,203,463
ink rgb(260,246,232),0
box 20,20,200,460
ink rgb(0,0,0),0
text 40,35,"MENU"
line 40,55,180,55


`Do right menu graphics
if "items" then ink rgb(120,102,200),0
box 253,23,623,463
ink rgb(260,246,232),0
box 250,20,620,460
ink rgb(0,0,0),0
text 270,35,"ITEM"
text 500,35,"QUANTITY"

`Do right menu graphics
if "save" then ink rgb(120,102,200),0
box 253,23,623,463
ink rgb(260,246,232),0
box 250,20,620,460
ink rgb(0,0,0),0


`Loop through sub menus
for x=1 to numSubMenus
`If the mouse is hovering it
if mousex()>40 and mousex()<40+text width(mainMenu$(x)) and mousey()>40+20*x and mousey()<40+20*x+text height(mainMenu$(x))
ink rgb(0,200,0),0
`If the mouse is clicked then switch menus to that one
if mouseclick()=1 then currentMenu=x
else
ink rgb(100,100,100),0
endif
`Print main menu text
text 40,40+20*x,mainMenu$(x)
next x

`Reset the 'cursor' for printing the text to the top of the list
listInc=0
`Loop through items
for x=1 to subMenuAmount(currentMenu)
`If the amount is more than 0
if subMenuQuantity(currentMenu,x)>0
`Move the 'cursor' for printing the text down, so we don't get overlapping text
inc listInc
`If mouse is hovering it
if mousex()>270 and mousex()<270+text width(subMenu$(currentMenu,x)) and mousey()>40+20*listInc and mousey()<40+20*listInc+text height(subMenu$(currentMenu,x))
ink rgb(255,255,0),0
`If the mouse is clicked and the time has passed from the last item click
if mouseclick()=1 and timer()-clickTimer>200
`Decriment the number of items
subMenuQuantity(currentMenu,x)=subMenuQuantity(currentMenu,x)-1
`Reset timer
clickTimer=timer()
endif
else
ink rgb(100,100,100),0
endif
`Print item name
text 270,40+20*listInc,subMenu$(currentMenu,x)
`Print item quantity
text 500,40+20*listInc,str$(subMenuQuantity(currentMenu,x))
endif
next x

sync
cls
loop

Chaos Games
AsriCE
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 4th Aug 2004 04:00
Okay, I've taken my time to try to solve your problems.

#1
Quote: "if "quit" then end"

You're comparing the string "quit" with nothing. The If-Then-Else-EndIf command is a conditional function. It checks if a variable matches with the condition you've set. The correct way would be:


The same goes with:
Quote: "
`Do right menu graphics
if "items" then ink rgb(120,102,200),0 <---------
box 253,23,623,463
ink rgb(260,246,232),0
box 250,20,620,460
ink rgb(0,0,0),0
text 270,35,"ITEM"
text 500,35,"QUANTITY"

`Do right menu graphics
if "save" then ink rgb(120,102,200),0 <-----------
box 253,23,623,463
ink rgb(260,246,232),0
box 250,20,620,460
ink rgb(0,0,0),0"


#2
Quote: "if "quit" then end"

Again the same line. Even if you did the correct way, the same problem will occur. This is because, that line will only be checked once. After the compiler passes the fifth line of your code, it will never ever read that line again. Why?? Because it is not in a loop. A loop will make the compiler to read the code again and again. Solution: Put that line in a your main loop.

#3
In your main loop, I've noticed you've put this line:
Quote: "if mouseclick()=1 then currentMenu=x"

The variable "currentMenu" will hold the menu number to the menu you've selected. I.E You select "save", currentMenu = 2. So, I've used this variable to set the conditions that you wish.

#4
One last thing. I really highly recommend that you indent your code. It makes it tidier and more organised



Final Code:


AsriCE Crew,
- Adi

There's only one hope.
gothboy 101
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Watonga, ok, usa
Posted: 4th Aug 2004 10:22
thank you for helping

Chaos Games
gothboy 101
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Watonga, ok, usa
Posted: 4th Aug 2004 10:26
ok heres my main question how would i get it to show the saved files in text

data "items",0
data "save",0
data "character",0
data "quit"
`Number of submenus
numSubMenus=5

`Where the sub menu names will be stored
dim mainMenu$(numSubMenus)
`Where the item names will be stored
dim subMenu$(numSubMenus,20)
`Where the amount of item will be stored
dim subMenuQuantity(numSubMenus,20)
`Where the amount of items in the sub menu will be stored
dim subMenuAmount(numSubMenus)

`Read in data
for x=1 to numSubMenus
read mainMenu$(x)
read subMenuAmount(x)
for y=1 to subMenuAmount(x)
read subMenu$(x,y)
subMenuQuantity(x,y)=rnd(10)+1
next y
next x

sync on

do
`Background
ink rgb(255,255,255),0
box 0,0,639,479

`Do left menu graphics
ink rgb(100,100,100),0
box 23,23,203,463
ink rgb(260,246,232),0
box 20,20,200,460
ink rgb(0,0,0),0
text 40,35,"MENU"
line 40,55,180,55

`Loop through sub menus
for x=1 to numSubMenus
`If the mouse is hovering it
if mousex()>40 and mousex()<40+text width(mainMenu$(x)) and mousey()>40+20*x and mousey()<40+20*x+text height(mainMenu$(x))
ink rgb(0,200,0),0
`If the mouse is clicked then switch menus to that one
if mouseclick()=1 then currentMenu=x
else
ink rgb(100,100,100),0
endif
`Print main menu text
text 40,40+20*x,mainMenu$(x)
next x

`Reset the 'cursor' for printing the text to the top of the list
listInc=0
`Loop through items
for x=1 to subMenuAmount(currentMenu)
`If the amount is more than 0
if subMenuQuantity(currentMenu,x)>0
`Move the 'cursor' for printing the text down, so we don't get overlapping text
inc listInc
`If mouse is hovering it
if mousex()>270 and mousex()<270+text width(subMenu$(currentMenu,x)) and mousey()>40+20*listInc and mousey()<40+20*listInc+text height(subMenu$(currentMenu,x))
ink rgb(255,255,0),0
`If the mouse is clicked and the time has passed from the last item click
if mouseclick()=1 and timer()-clickTimer>200
`Decriment the number of items
subMenuQuantity(currentMenu,x)=subMenuQuantity(currentMenu,x)-1
`Reset timer
clickTimer=timer()
endif
else
ink rgb(100,100,100),0
endif
`Print item name
text 270,40+20*listInc,subMenu$(currentMenu,x)
`Print item quantity
text 500,40+20*listInc,str$(subMenuQuantity(currentMenu,x))
endif
next x

REM HERE'S WHAT I'VE CHANGED -------------------------------------
if currentMenu=1
`Do right menu graphics
if "items" then ink rgb(120,102,200),0
box 253,23,623,463
ink rgb(260,246,232),0
box 250,20,620,460
ink rgb(0,0,0),0
text 270,35,"ITEM"
text 500,35,"QUANTITY"
EndIf

if currentMenu=2
`Do right menu graphics
if "save" then ink rgb(120,102,200),0
box 253,23,623,463
ink rgb(260,246,232),0
box 250,20,620,460
ink rgb(0,0,0),0
if keystate(31) = 1
filename$ = "currentsave.save"
if file exist (filename$) = 1 then delete file filename$
open to write 1, filename$
savadata1# = object position x(1)
savadata2# = object position y(1)
savadata3# = object position z(1)
write float 1,savadata1#
write float 1,savadata2#
write float 1,savadata3#
close file 1
endif

endIf

if currentMenu=4 then end

sync
cls
loop

Chaos Games

Login to post a reply

Server time is: 2024-09-22 19:22:40
Your offset time is: 2024-09-22 19:22:40