WHY ISN'T THIS WORKING??? All I need is my main menu to work, and then I can head on to the new game menu, once I have the basics. I HAD this working earlier, but I ran into a snag, changed some things, screwed it up, and now it's not working!
It's supposed to create the four main menu buttons, and put invisible buttons (in two parts) over the top of the buttons, that highlight when AND ONLY WHEN the cursor is over the button. What IS happening is that the button highlights, then STAYS highlighted. Why? Why, why, why, why, why???
It's supposed to create the four main menu buttons, and put invisible buttons (in two parts) over the top of the buttons, that highlight when AND ONLY WHEN the cursor is over the button. What IS happening is that the button highlights, then STAYS highlighted. Why? Why, why, why, why, why???
Code:
include, plotscr.hsd
include, Alliance.hsi
global variable (0, mouse cursor)
global variable (1, load_game)
global variable (2, new_game)
global variable (3, options)
global variable (4, quit_but)
global variable (5, loadbut_l)
global variable (6, newbut_l)
global variable (7, optbut_l)
global variable (8, quitbut_l)
global variable (9, loadbut_r)
global variable (10, newbut_r)
global variable (11, optbut_r)
global variable (12, quitbut_r)
global variable (13, chargenwalk_u)
global variable (14, chargenwalk_d)
global variable (15, chargenwalk_l)
global variable (16, chargenwalk_r)
define constant (0, timer:mouse)
plotscript, new game, begin
suspend player
init mouse
mouse region (-1, -1, -1, -1)
mouse cursor := load walkabout sprite (0)
menu1 loop
end
script, menu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
menu1 slices
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @menu1 loop)
end
script, menu1 slices, begin
load_game := create rect (119, 45)
new_game := create rect (113, 45)
options := create rect (107, 45)
quit_but := create rect (101, 45)
put slice (load_game, 110, 80)
put slice (new_game, 113, 110)
put slice (options, 116, 140)
put slice (quit_but, 119, 170)
set slice visible (load_game, off)
set slice visible (new_game, off)
set slice visible (options, off)
set slice visible (quit_but, off)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
loadbut_l := load large enemy sprite (1)
newbut_l := load large enemy sprite (3)
optbut_l := load large enemy sprite (5)
quitbut_l := load large enemy sprite (7)
loadbut_r := load large enemy sprite (2)
newbut_r := load large enemy sprite (4)
optbut_r := load large enemy sprite (6)
quitbut_r := load large enemy sprite (8)
put slice (loadbut_l, 80, 80)
put slice (newbut_l, 80, 110)
put slice (optbut_l, 80, 140)
put slice (quitbut_l, 80, 170)
put slice (loadbut_r, 160, 80)
put slice (newbut_r, 160, 110)
put slice (optbut_r, 160, 140)
put slice (quitbut_r, 160, 170)
set slice visible (loadbut_l, off)
set slice visible (newbut_l, off)
set slice visible (optbut_l, off)
set slice visible (quitbut_l, off)
set slice visible (loadbut_r, off)
set slice visible (newbut_r, off)
set slice visible (optbut_r, off)
set slice visible (quitbut_r, off)
if (slice contains (load_game, mouse cursor)) then (set slice visible (loadbut_l, on)), (set slice visible (loadbut_r, on))
if (slice contains (new_game, mouse cursor)) then (set slice visible (newbut_l, on)), (set slice visible (newbut_r, on))
if (slice contains (options, mouse cursor)) then (set slice visible (optbut_l, on)), (set slice visible (optbut_r, on))
if (slice contains (quit_but, mouse cursor)) then (set slice visible (quitbut_l, on)), (set slice visible (quitbut_r, on))
end
include, Alliance.hsi
global variable (0, mouse cursor)
global variable (1, load_game)
global variable (2, new_game)
global variable (3, options)
global variable (4, quit_but)
global variable (5, loadbut_l)
global variable (6, newbut_l)
global variable (7, optbut_l)
global variable (8, quitbut_l)
global variable (9, loadbut_r)
global variable (10, newbut_r)
global variable (11, optbut_r)
global variable (12, quitbut_r)
global variable (13, chargenwalk_u)
global variable (14, chargenwalk_d)
global variable (15, chargenwalk_l)
global variable (16, chargenwalk_r)
define constant (0, timer:mouse)
plotscript, new game, begin
suspend player
init mouse
mouse region (-1, -1, -1, -1)
mouse cursor := load walkabout sprite (0)
menu1 loop
end
script, menu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
menu1 slices
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @menu1 loop)
end
script, menu1 slices, begin
load_game := create rect (119, 45)
new_game := create rect (113, 45)
options := create rect (107, 45)
quit_but := create rect (101, 45)
put slice (load_game, 110, 80)
put slice (new_game, 113, 110)
put slice (options, 116, 140)
put slice (quit_but, 119, 170)
set slice visible (load_game, off)
set slice visible (new_game, off)
set slice visible (options, off)
set slice visible (quit_but, off)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
loadbut_l := load large enemy sprite (1)
newbut_l := load large enemy sprite (3)
optbut_l := load large enemy sprite (5)
quitbut_l := load large enemy sprite (7)
loadbut_r := load large enemy sprite (2)
newbut_r := load large enemy sprite (4)
optbut_r := load large enemy sprite (6)
quitbut_r := load large enemy sprite (8)
put slice (loadbut_l, 80, 80)
put slice (newbut_l, 80, 110)
put slice (optbut_l, 80, 140)
put slice (quitbut_l, 80, 170)
put slice (loadbut_r, 160, 80)
put slice (newbut_r, 160, 110)
put slice (optbut_r, 160, 140)
put slice (quitbut_r, 160, 170)
set slice visible (loadbut_l, off)
set slice visible (newbut_l, off)
set slice visible (optbut_l, off)
set slice visible (quitbut_l, off)
set slice visible (loadbut_r, off)
set slice visible (newbut_r, off)
set slice visible (optbut_r, off)
set slice visible (quitbut_r, off)
if (slice contains (load_game, mouse cursor)) then (set slice visible (loadbut_l, on)), (set slice visible (loadbut_r, on))
if (slice contains (new_game, mouse cursor)) then (set slice visible (newbut_l, on)), (set slice visible (newbut_r, on))
if (slice contains (options, mouse cursor)) then (set slice visible (optbut_l, on)), (set slice visible (optbut_r, on))
if (slice contains (quit_but, mouse cursor)) then (set slice visible (quitbut_l, on)), (set slice visible (quitbut_r, on))
end
your "menu1 slices" script is being called once every tick by the "menu1 loop" script. it re-creates all of your slices on every tick. That is why you are seeing strange button behavior, because instead of just updating the four buttons, you are creating four new buttons on every tick. If you leave your menu running long enough, it will run out of memory and crash because of all the hundreds of thousands of slices.
Make a new script called "menu 1 create" and do all the slice creation there. Then "menu1 slices" should only manipulate slices that already exist.
Make a new script called "menu 1 create" and do all the slice creation there. Then "menu1 slices" should only manipulate slices that already exist.
Um... fixed that. Still got the problem:
Code:
include, plotscr.hsd
include, Alliance.hsi
global variable (0, mouse cursor)
global variable (1, load_game)
global variable (2, new_game)
global variable (3, options)
global variable (4, quit_but)
global variable (5, loadbut_l)
global variable (6, newbut_l)
global variable (7, optbut_l)
global variable (8, quitbut_l)
global variable (9, loadbut_r)
global variable (10, newbut_r)
global variable (11, optbut_r)
global variable (12, quitbut_r)
global variable (13, chargenwalk_u)
global variable (14, chargenwalk_d)
global variable (15, chargenwalk_l)
global variable (16, chargenwalk_r)
define constant (0, timer:mouse)
#----------------------------------------------------------------------------------------------------
plotscript, new game, begin
suspend player
init mouse
mouse region (-1, -1, -1, -1)
mouse cursor := load walkabout sprite (0)
menu1 create
end
#----------------------------------------------------------------------------------------------------
script, menu1 create, begin
load_game := create rect (119, 45)
new_game := create rect (113, 45)
options := create rect (107, 45)
quit_but := create rect (101, 45)
put slice (load_game, 110, 80)
put slice (new_game, 113, 110)
put slice (options, 116, 140)
put slice (quit_but, 119, 170)
set slice visible (load_game, off)
set slice visible (new_game, off)
set slice visible (options, off)
set slice visible (quit_but, off)
loadbut_l := load large enemy sprite (1)
newbut_l := load large enemy sprite (3)
optbut_l := load large enemy sprite (5)
quitbut_l := load large enemy sprite (7)
loadbut_r := load large enemy sprite (2)
newbut_r := load large enemy sprite (4)
optbut_r := load large enemy sprite (6)
quitbut_r := load large enemy sprite (8)
put slice (loadbut_l, 80, 80)
put slice (newbut_l, 80, 110)
put slice (optbut_l, 80, 140)
put slice (quitbut_l, 80, 170)
put slice (loadbut_r, 160, 80)
put slice (newbut_r, 160, 110)
put slice (optbut_r, 160, 140)
put slice (quitbut_r, 160, 170)
set slice visible (loadbut_l, off)
set slice visible (newbut_l, off)
set slice visible (optbut_l, off)
set slice visible (quitbut_l, off)
set slice visible (loadbut_r, off)
set slice visible (newbut_r, off)
set slice visible (optbut_r, off)
set slice visible (quitbut_r, off)
menu1 loop
end
#----------------------------------------------------------------------------------------------------
script, menu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
menu1 butbehave
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @menu1 loop)
end
#----------------------------------------------------------------------------------------------------
script, menu1 butbehave, begin
if (slice contains (load_game, mouse cursor)) then ((set slice visible (loadbut_l, on)), (set slice visible (loadbut_r, on)))
if (slice contains (new_game, mouse cursor)) then ((set slice visible (newbut_l, on)), (set slice visible (newbut_r, on)))
if (slice contains (options, mouse cursor)) then ((set slice visible (optbut_l, on)), (set slice visible (optbut_r, on)))
if (slice contains (quit_but, mouse cursor)) then ((set slice visible (quitbut_l, on)), (set slice visible (quitbut_r, on)))
end
include, Alliance.hsi
global variable (0, mouse cursor)
global variable (1, load_game)
global variable (2, new_game)
global variable (3, options)
global variable (4, quit_but)
global variable (5, loadbut_l)
global variable (6, newbut_l)
global variable (7, optbut_l)
global variable (8, quitbut_l)
global variable (9, loadbut_r)
global variable (10, newbut_r)
global variable (11, optbut_r)
global variable (12, quitbut_r)
global variable (13, chargenwalk_u)
global variable (14, chargenwalk_d)
global variable (15, chargenwalk_l)
global variable (16, chargenwalk_r)
define constant (0, timer:mouse)
#----------------------------------------------------------------------------------------------------
plotscript, new game, begin
suspend player
init mouse
mouse region (-1, -1, -1, -1)
mouse cursor := load walkabout sprite (0)
menu1 create
end
#----------------------------------------------------------------------------------------------------
script, menu1 create, begin
load_game := create rect (119, 45)
new_game := create rect (113, 45)
options := create rect (107, 45)
quit_but := create rect (101, 45)
put slice (load_game, 110, 80)
put slice (new_game, 113, 110)
put slice (options, 116, 140)
put slice (quit_but, 119, 170)
set slice visible (load_game, off)
set slice visible (new_game, off)
set slice visible (options, off)
set slice visible (quit_but, off)
loadbut_l := load large enemy sprite (1)
newbut_l := load large enemy sprite (3)
optbut_l := load large enemy sprite (5)
quitbut_l := load large enemy sprite (7)
loadbut_r := load large enemy sprite (2)
newbut_r := load large enemy sprite (4)
optbut_r := load large enemy sprite (6)
quitbut_r := load large enemy sprite (8)
put slice (loadbut_l, 80, 80)
put slice (newbut_l, 80, 110)
put slice (optbut_l, 80, 140)
put slice (quitbut_l, 80, 170)
put slice (loadbut_r, 160, 80)
put slice (newbut_r, 160, 110)
put slice (optbut_r, 160, 140)
put slice (quitbut_r, 160, 170)
set slice visible (loadbut_l, off)
set slice visible (newbut_l, off)
set slice visible (optbut_l, off)
set slice visible (quitbut_l, off)
set slice visible (loadbut_r, off)
set slice visible (newbut_r, off)
set slice visible (optbut_r, off)
set slice visible (quitbut_r, off)
menu1 loop
end
#----------------------------------------------------------------------------------------------------
script, menu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (main menu)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
menu1 butbehave
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @menu1 loop)
end
#----------------------------------------------------------------------------------------------------
script, menu1 butbehave, begin
if (slice contains (load_game, mouse cursor)) then ((set slice visible (loadbut_l, on)), (set slice visible (loadbut_r, on)))
if (slice contains (new_game, mouse cursor)) then ((set slice visible (newbut_l, on)), (set slice visible (newbut_r, on)))
if (slice contains (options, mouse cursor)) then ((set slice visible (optbut_l, on)), (set slice visible (optbut_r, on)))
if (slice contains (quit_but, mouse cursor)) then ((set slice visible (quitbut_l, on)), (set slice visible (quitbut_r, on)))
end
Okay, good Looks much better now.
I can see the other problem.
This makes the button slices visible when the mouse is over them, but it does not make them invisible when the mouse is not over them. Try something like this:
Of course, you could simplify this and do it with no "if" commands. Check this out:
So this does the same thing... I don't know if this looks more or less clear to you than the other way of doing it. (The speed is going to be so close to the same that it doesn't matter, so just go for the method that looks easiest to read for you)
I can see the other problem.
Code:
script, menu1 butbehave, begin
if (slice contains (load_game, mouse cursor)) then ((set slice visible (loadbut_l, on)), (set slice visible (loadbut_r, on)))
if (slice contains (new_game, mouse cursor)) then ((set slice visible (newbut_l, on)), (set slice visible (newbut_r, on)))
if (slice contains (options, mouse cursor)) then ((set slice visible (optbut_l, on)), (set slice visible (optbut_r, on)))
if (slice contains (quit_but, mouse cursor)) then ((set slice visible (quitbut_l, on)), (set slice visible (quitbut_r, on)))
end
script, menu1 butbehave, begin
if (slice contains (load_game, mouse cursor)) then ((set slice visible (loadbut_l, on)), (set slice visible (loadbut_r, on)))
if (slice contains (new_game, mouse cursor)) then ((set slice visible (newbut_l, on)), (set slice visible (newbut_r, on)))
if (slice contains (options, mouse cursor)) then ((set slice visible (optbut_l, on)), (set slice visible (optbut_r, on)))
if (slice contains (quit_but, mouse cursor)) then ((set slice visible (quitbut_l, on)), (set slice visible (quitbut_r, on)))
end
This makes the button slices visible when the mouse is over them, but it does not make them invisible when the mouse is not over them. Try something like this:
Code:
if (slice contains (load_game, mouse cursor))
then (set slice visible (loadbut_l, on), set slice visible (loadbut_r, on))
else (set slice visible (loadbut_l, off), set slice visible (loadbut_r, off))
then (set slice visible (loadbut_l, on), set slice visible (loadbut_r, on))
else (set slice visible (loadbut_l, off), set slice visible (loadbut_r, off))
Of course, you could simplify this and do it with no "if" commands. Check this out:
Code:
script, menu1 butbehave, begin
set slice visible(loadbut_l, slice contains(load_game, mouse cursor))
set slice visible(loadbut_r, slice contains(load_game, mouse cursor))
set slice visible(newbut_l, slice contains(new_game, mouse cursor))
set slice visible(newbut_r, slice contains(new_game, mouse cursor))
set slice visible(optbut_l, slice contains(options, mouse cursor))
set slice visible(optbut_r, slice contains(options, mouse cursor))
set slice visible(quitbut_l, slice contains(quit_but, mouse cursor))
set slice visible(quitbut_r, slice contains(quit_but, mouse cursor))
end
set slice visible(loadbut_l, slice contains(load_game, mouse cursor))
set slice visible(loadbut_r, slice contains(load_game, mouse cursor))
set slice visible(newbut_l, slice contains(new_game, mouse cursor))
set slice visible(newbut_r, slice contains(new_game, mouse cursor))
set slice visible(optbut_l, slice contains(options, mouse cursor))
set slice visible(optbut_r, slice contains(options, mouse cursor))
set slice visible(quitbut_l, slice contains(quit_but, mouse cursor))
set slice visible(quitbut_r, slice contains(quit_but, mouse cursor))
end
So this does the same thing... I don't know if this looks more or less clear to you than the other way of doing it. (The speed is going to be so close to the same that it doesn't matter, so just go for the method that looks easiest to read for you)
(One step closer... Yes!)
Okay, so it's now working (thank you, thank you...). I'm assuming that the piece you have at the end...
... means "set slice visible (this slice, when (this is true))"
Anyways, on to the two problems that threw me for a loop, which set this whole mess into motion:
1. I have four 20x20 squares, and I want an animated walkabout of the current look for the character, one direction per square (e.g. one square has the walkabout walk forward, one square has the walkabout walk away... etc.). How would this be done? I can't figure out how to do it with either NPCs OR hero commands.
2. Um... when I drop into the next menu... the main menu buttons are still there. Even when I free the slices. Even when I use a new mouse loop. Even when I have a separate variable for each menu, switch each variable depending on the menu the player is on, and set in the main script to go to a certain group that creates the correct slices. (Although I suspect I did the final one wrong).
Also, is there a command that does the equivalent of "free ALL slices"?
Okay, so it's now working (thank you, thank you...). I'm assuming that the piece you have at the end...
Code:
set slice visible(loadbut_l, slice contains(load_game, mouse cursor)
... means "set slice visible (this slice, when (this is true))"
Anyways, on to the two problems that threw me for a loop, which set this whole mess into motion:
1. I have four 20x20 squares, and I want an animated walkabout of the current look for the character, one direction per square (e.g. one square has the walkabout walk forward, one square has the walkabout walk away... etc.). How would this be done? I can't figure out how to do it with either NPCs OR hero commands.
2. Um... when I drop into the next menu... the main menu buttons are still there. Even when I free the slices. Even when I use a new mouse loop. Even when I have a separate variable for each menu, switch each variable depending on the menu the player is on, and set in the main script to go to a certain group that creates the correct slices. (Although I suspect I did the final one wrong).
Also, is there a command that does the equivalent of "free ALL slices"?
J_Taylor wrote:
... means "set slice visible (this slice, when (this is true))"
Code:
set slice visible(loadbut_l, slice contains(load_game, mouse cursor)
... means "set slice visible (this slice, when (this is true))"
Exactly. Any command that returns a true/false result can be used in a place where you need an on/off value.
J_Taylor wrote:
1. I have four 20x20 squares, and I want an animated walkabout of the current look for the character, one direction per square (e.g. one square has the walkabout walk forward, one square has the walkabout walk away... etc.). How would this be done? I can't figure out how to do it with either NPCs OR hero commands.
I would do it with an NPC. You can have one NPC definition, and put four copies on the screen using "create NPC". When you do an "alter NPC" command to change the picture and palette, all four of them would change at the same time.
J_Taylor wrote:
2. Um... when I drop into the next menu... the main menu buttons are still there. Even when I free the slices. Even when I use a new mouse loop. Even when I have a separate variable for each menu, switch each variable depending on the menu the player is on, and set in the main script to go to a certain group that creates the correct slices. (Although I suspect I did the final one wrong).
Are you positive that "menu1 create" is only being run once?
Could I see the code where you free the slices?
J_Taylor wrote:
Also, is there a command that does the equivalent of "free ALL slices"?
Sort of, yes. The "free slice children" command will free all the children of a slice (but not the slice itself). Because you don't seem to be doing any reparenting, you can just do "free slice children(sprite layer)" and it will free all of your slices because they are all the children of the sprite layer (which is the default parent)
Code:
include, plotscr.hsd
include, Alliance.hsi
global variable (0, mouse cursor)
global variable (1, load_game)
global variable (2, new_game)
global variable (3, options)
global variable (4, quit_but)
global variable (5, loadbut_l)
global variable (6, newbut_l)
global variable (7, optbut_l)
global variable (8, quitbut_l)
global variable (9, loadbut_r)
global variable (10, newbut_r)
global variable (11, optbut_r)
global variable (12, quitbut_r)
global variable (13, chargenwalk_u)
global variable (14, chargenwalk_d)
global variable (15, chargenwalk_l)
global variable (16, chargenwalk_r)
global variable (17, mmenu1)
global variable (18, cmenu1)
global variable (19, cmenu2)
global variable (20, omenu1)
define constant (0, timer:mouse)
#----------------------------------------------------------------------------------------------------
plotscript, new game, begin
suspend player
init mouse
mouse region (-1, -1, -1, -1)
mouse cursor := load walkabout sprite (0)
set variable (mmenu1, on)
set variable (cmenu1, off)
set variable (cmenu2, off)
set variable (omenu1, off)
menu hub
end
#----------------------------------------------------------------------------------------------------
script, menu hub, begin
if (mmenu1 == on) then (mmenu1 create)
if (cmenu1 == on) then (cmenu1 create)
# if (cmenu2 == on) then (cmenu2 create)
# if (omenu1 == on) then (omenu1 create)
end
#----------------------------------------------------------------------------------------------------
script, mmenu1 create, begin
load_game := create rect (119, 45)
new_game := create rect (113, 45)
options := create rect (107, 45)
quit_but := create rect (101, 45)
put slice (load_game, 110, 80)
put slice (new_game, 113, 110)
put slice (options, 116, 140)
put slice (quit_but, 119, 170)
set slice visible (load_game, off)
set slice visible (new_game, off)
set slice visible (options, off)
set slice visible (quit_but, off)
loadbut_l := load large enemy sprite (1)
newbut_l := load large enemy sprite (3)
optbut_l := load large enemy sprite (5)
quitbut_l := load large enemy sprite (7)
loadbut_r := load large enemy sprite (2)
newbut_r := load large enemy sprite (4)
optbut_r := load large enemy sprite (6)
quitbut_r := load large enemy sprite (8)
put slice (loadbut_l, 80, 80)
put slice (newbut_l, 80, 110)
put slice (optbut_l, 80, 140)
put slice (quitbut_l, 80, 170)
put slice (loadbut_r, 160, 80)
put slice (newbut_r, 160, 110)
put slice (optbut_r, 160, 140)
put slice (quitbut_r, 160, 170)
set slice visible (loadbut_l, off)
set slice visible (newbut_l, off)
set slice visible (optbut_l, off)
set slice visible (quitbut_l, off)
set slice visible (loadbut_r, off)
set slice visible (newbut_r, off)
set slice visible (optbut_r, off)
set slice visible (quitbut_r, off)
menu1 loop
end
#----------------------------------------------------------------------------------------------------
script, menu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), menu hub)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), set variable (cmenu1, on), menu hub)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), menu hub)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
menu1 butbehave
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @menu1 loop)
end
#----------------------------------------------------------------------------------------------------
script, menu1 butbehave, begin
set slice visible(loadbut_l, slice contains(load_game, mouse cursor))
set slice visible(loadbut_r, slice contains(load_game, mouse cursor))
set slice visible(newbut_l, slice contains(new_game, mouse cursor))
set slice visible(newbut_r, slice contains(new_game, mouse cursor))
set slice visible(optbut_l, slice contains(options, mouse cursor))
set slice visible(optbut_r, slice contains(options, mouse cursor))
set slice visible(quitbut_l, slice contains(quit_but, mouse cursor))
set slice visible(quitbut_r, slice contains(quit_but, mouse cursor))
end
#----------------------------------------------------------------------------------------------------
script, cmenu1 create, begin
free slice children (sprite layer)
use door (0)
cmenu1 loop
end
#----------------------------------------------------------------------------------------------------
script, cmenu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (set variable (cmenu1, off), menu hub)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (set variable (cmenu1, off), menu hub)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (set variable (cmenu1, off), menu hub)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @cmenu1 loop)
end
include, Alliance.hsi
global variable (0, mouse cursor)
global variable (1, load_game)
global variable (2, new_game)
global variable (3, options)
global variable (4, quit_but)
global variable (5, loadbut_l)
global variable (6, newbut_l)
global variable (7, optbut_l)
global variable (8, quitbut_l)
global variable (9, loadbut_r)
global variable (10, newbut_r)
global variable (11, optbut_r)
global variable (12, quitbut_r)
global variable (13, chargenwalk_u)
global variable (14, chargenwalk_d)
global variable (15, chargenwalk_l)
global variable (16, chargenwalk_r)
global variable (17, mmenu1)
global variable (18, cmenu1)
global variable (19, cmenu2)
global variable (20, omenu1)
define constant (0, timer:mouse)
#----------------------------------------------------------------------------------------------------
plotscript, new game, begin
suspend player
init mouse
mouse region (-1, -1, -1, -1)
mouse cursor := load walkabout sprite (0)
set variable (mmenu1, on)
set variable (cmenu1, off)
set variable (cmenu2, off)
set variable (omenu1, off)
menu hub
end
#----------------------------------------------------------------------------------------------------
script, menu hub, begin
if (mmenu1 == on) then (mmenu1 create)
if (cmenu1 == on) then (cmenu1 create)
# if (cmenu2 == on) then (cmenu2 create)
# if (omenu1 == on) then (omenu1 create)
end
#----------------------------------------------------------------------------------------------------
script, mmenu1 create, begin
load_game := create rect (119, 45)
new_game := create rect (113, 45)
options := create rect (107, 45)
quit_but := create rect (101, 45)
put slice (load_game, 110, 80)
put slice (new_game, 113, 110)
put slice (options, 116, 140)
put slice (quit_but, 119, 170)
set slice visible (load_game, off)
set slice visible (new_game, off)
set slice visible (options, off)
set slice visible (quit_but, off)
loadbut_l := load large enemy sprite (1)
newbut_l := load large enemy sprite (3)
optbut_l := load large enemy sprite (5)
quitbut_l := load large enemy sprite (7)
loadbut_r := load large enemy sprite (2)
newbut_r := load large enemy sprite (4)
optbut_r := load large enemy sprite (6)
quitbut_r := load large enemy sprite (8)
put slice (loadbut_l, 80, 80)
put slice (newbut_l, 80, 110)
put slice (optbut_l, 80, 140)
put slice (quitbut_l, 80, 170)
put slice (loadbut_r, 160, 80)
put slice (newbut_r, 160, 110)
put slice (optbut_r, 160, 140)
put slice (quitbut_r, 160, 170)
set slice visible (loadbut_l, off)
set slice visible (newbut_l, off)
set slice visible (optbut_l, off)
set slice visible (quitbut_l, off)
set slice visible (loadbut_r, off)
set slice visible (newbut_r, off)
set slice visible (optbut_r, off)
set slice visible (quitbut_r, off)
menu1 loop
end
#----------------------------------------------------------------------------------------------------
script, menu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), menu hub)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), set variable (cmenu1, on), menu hub)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), menu hub)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
menu1 butbehave
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @menu1 loop)
end
#----------------------------------------------------------------------------------------------------
script, menu1 butbehave, begin
set slice visible(loadbut_l, slice contains(load_game, mouse cursor))
set slice visible(loadbut_r, slice contains(load_game, mouse cursor))
set slice visible(newbut_l, slice contains(new_game, mouse cursor))
set slice visible(newbut_r, slice contains(new_game, mouse cursor))
set slice visible(optbut_l, slice contains(options, mouse cursor))
set slice visible(optbut_r, slice contains(options, mouse cursor))
set slice visible(quitbut_l, slice contains(quit_but, mouse cursor))
set slice visible(quitbut_r, slice contains(quit_but, mouse cursor))
end
#----------------------------------------------------------------------------------------------------
script, cmenu1 create, begin
free slice children (sprite layer)
use door (0)
cmenu1 loop
end
#----------------------------------------------------------------------------------------------------
script, cmenu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (set variable (cmenu1, off), menu hub)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (set variable (cmenu1, off), menu hub)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (set variable (cmenu1, off), menu hub)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @cmenu1 loop)
end
I'm still getting alerts. Also, I'm seriously considering using another few notepad documents. There's a little too much right here...
What sort of alerts are you getting?
Also, I just noticed something. When you free all of the slices, the mouse cursor slice gets freed too.
One way to handle this is to re-create the mouse cursor after you free all the slices.
Another way is to put all of the other slices in a container. Then you can just free the container.
Also, have you seen the "load slice collection" command? You could design your menu in the slice collection editor, and then greatly simplify the "menu1 create" script
All the positioning and default visibility is done using the slice collection editor. You assign lookup codenames to the slices that you will need handles for, and then you lookup slice to get the handles.
You don't have to do it this way, the way you are doing ti already is perfectly fine, but since you said you were concerned about the script getting long, I thought this might help.
Also, I just noticed something. When you free all of the slices, the mouse cursor slice gets freed too.
One way to handle this is to re-create the mouse cursor after you free all the slices.
Another way is to put all of the other slices in a container. Then you can just free the container.
Also, have you seen the "load slice collection" command? You could design your menu in the slice collection editor, and then greatly simplify the "menu1 create" script
Code:
script, mmenu1 create, begin
variable(sl)
sl := load slice collection(0)
load_game := lookup slice(sli:load_game, sl)
new_game := lookup slice(sli:new_game, sl)
options := lookup slice(sli:options, sl)
quit_but := lookup slice(sli:quit_but, sl)
loadbut_l := lookup slice(sli:loadbut_l, sl)
newbut_l := lookup slice(sli:newbut_l, sl)
optbut_l := lookup slice(sli:optbut_l, sl)
quitbut_l := lookup slice(sli:quitbut_l, sl)
loadbut_r := lookup slice(sli:loadbut_r, sl)
newbut_r := lookup slice(sli:newbut_r, sl)
optbut_r := lookup slice(sli:optbut_l, sl)
quitbut_r := lookup slice(sli:quitbut_l, sl)
menu1 loop
end
script, mmenu1 create, begin
variable(sl)
sl := load slice collection(0)
load_game := lookup slice(sli:load_game, sl)
new_game := lookup slice(sli:new_game, sl)
options := lookup slice(sli:options, sl)
quit_but := lookup slice(sli:quit_but, sl)
loadbut_l := lookup slice(sli:loadbut_l, sl)
newbut_l := lookup slice(sli:newbut_l, sl)
optbut_l := lookup slice(sli:optbut_l, sl)
quitbut_l := lookup slice(sli:quitbut_l, sl)
loadbut_r := lookup slice(sli:loadbut_r, sl)
newbut_r := lookup slice(sli:newbut_r, sl)
optbut_r := lookup slice(sli:optbut_l, sl)
quitbut_r := lookup slice(sli:quitbut_l, sl)
menu1 loop
end
All the positioning and default visibility is done using the slice collection editor. You assign lookup codenames to the slices that you will need handles for, and then you lookup slice to get the handles.
You don't have to do it this way, the way you are doing ti already is perfectly fine, but since you said you were concerned about the script getting long, I thought this might help.
The alerts I'm getting still say that the program is trying to load the deleted slices.
I tried using the slice collection editor, but I ran into a few snags. First one being that I can't figure out how to attach a lookup code to a slice inside the editor. How do I specify which slice I'm referring to?
As to the slice container idea... I don't know how to do that, but I'll give it a shot later.
I tried using the slice collection editor, but I ran into a few snags. First one being that I can't figure out how to attach a lookup code to a slice inside the editor. How do I specify which slice I'm referring to?
As to the slice container idea... I don't know how to do that, but I'll give it a shot later.
J_Taylor wrote:
The alerts I'm getting still say that the program is trying to load the deleted slices.
Do you mean "slice handle # has already been deleted" ?
That might be a side effect of deleting the mouse cursor when you free the other slices.
J_Taylor wrote:
I tried using the slice collection editor, but I ran into a few snags. First one being that I can't figure out how to attach a lookup code to a slice inside the editor. How do I specify which slice I'm referring to?
When you are editing a slice, you see where it says "Lookup code: none" ? Press ENTER on that, and you will go to a screen with a blue line. type the codename there. (I suggest using the same names as the global variables that you plan to save the slice handles in, but really you could use any name) after you type the name, press enter again to confirm.
If you have any more troubles with that, let me know.
Code:
include, plotscr.hsd
include, Alliance.hsi
global variable (0, mouse cursor)
global variable (1, load_game)
global variable (2, new_game)
global variable (3, options)
global variable (4, quit_but)
global variable (5, loadbut_l)
global variable (6, newbut_l)
global variable (7, optbut_l)
global variable (8, quitbut_l)
global variable (9, loadbut_r)
global variable (10, newbut_r)
global variable (11, optbut_r)
global variable (12, quitbut_r)
global variable (13, chargenwalk_u)
global variable (14, chargenwalk_d)
global variable (15, chargenwalk_l)
global variable (16, chargenwalk_r)
global variable (17, mmenu1)
global variable (18, cmenu1)
global variable (19, cmenu2)
global variable (20, omenu1)
global variable (21, mmenu1slices)
define constant (0, timer:mouse)
#----------------------------------------------------------------------------------------------------
plotscript, new game, begin
suspend player
init mouse
mouse region (-1, -1, -1, -1)
mouse cursor := load walkabout sprite (0)
set variable (mmenu1, on)
set variable (cmenu1, off)
set variable (cmenu2, off)
set variable (omenu1, off)
menu hub
end
#----------------------------------------------------------------------------------------------------
script, menu hub, begin
if (mmenu1 == on) then (mmenu1 create)
if (cmenu1 == on) then (cmenu1 create)
# if (cmenu2 == on) then (cmenu2 create)
# if (omenu1 == on) then (omenu1 create)
end
#----------------------------------------------------------------------------------------------------
script, mmenu1 create, begin
mmenu1slices := create container (320, 200)
load_game := create rect (119, 45)
set parent (load_game, mmenu1slices)
new_game := create rect (113, 45)
set parent (new_game, mmenu1slices)
options := create rect (107, 45)
set parent (options, mmenu1slices)
quit_but := create rect (101, 45)
set parent (quit_but, mmenu1slices)
put slice (load_game, 110, 80)
put slice (new_game, 113, 110)
put slice (options, 116, 140)
put slice (quit_but, 119, 170)
set slice visible (load_game, off)
set slice visible (new_game, off)
set slice visible (options, off)
set slice visible (quit_but, off)
loadbut_l := load large enemy sprite (1)
set parent (loadbut_l, mmenu1slices)
newbut_l := load large enemy sprite (3)
set parent (newbut_l, mmenu1slices)
optbut_l := load large enemy sprite (5)
set parent (optbut_l, mmenu1slices)
quitbut_l := load large enemy sprite (7)
set parent (quitbut_l, mmenu1slices)
loadbut_r := load large enemy sprite (2)
set parent (loadbut_r, mmenu1slices)
newbut_r := load large enemy sprite (4)
set parent (newbut_r, mmenu1slices)
optbut_r := load large enemy sprite (6)
set parent (optbut_r, mmenu1slices)
quitbut_r := load large enemy sprite (8)
set parent (quitbut_r, mmenu1slices)
put slice (loadbut_l, 80, 80)
put slice (newbut_l, 80, 110)
put slice (optbut_l, 80, 140)
put slice (quitbut_l, 80, 170)
put slice (loadbut_r, 160, 80)
put slice (newbut_r, 160, 110)
put slice (optbut_r, 160, 140)
put slice (quitbut_r, 160, 170)
set slice visible (loadbut_l, off)
set slice visible (newbut_l, off)
set slice visible (optbut_l, off)
set slice visible (quitbut_l, off)
set slice visible (loadbut_r, off)
set slice visible (newbut_r, off)
set slice visible (optbut_r, off)
set slice visible (quitbut_r, off)
menu1 loop
end
#----------------------------------------------------------------------------------------------------
script, menu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), menu hub)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), set variable (cmenu1, on), menu hub)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), menu hub)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
menu1 butbehave
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @menu1 loop)
end
#----------------------------------------------------------------------------------------------------
script, menu1 butbehave, begin
set slice visible(loadbut_l, slice contains(load_game, mouse cursor))
set slice visible(loadbut_r, slice contains(load_game, mouse cursor))
set slice visible(newbut_l, slice contains(new_game, mouse cursor))
set slice visible(newbut_r, slice contains(new_game, mouse cursor))
set slice visible(optbut_l, slice contains(options, mouse cursor))
set slice visible(optbut_r, slice contains(options, mouse cursor))
set slice visible(quitbut_l, slice contains(quit_but, mouse cursor))
set slice visible(quitbut_r, slice contains(quit_but, mouse cursor))
end
#----------------------------------------------------------------------------------------------------
script, cmenu1 create, begin
free slice (mmenu1 slices)
use door (0)
end
#----------------------------------------------------------------------------------------------------
include, Alliance.hsi
global variable (0, mouse cursor)
global variable (1, load_game)
global variable (2, new_game)
global variable (3, options)
global variable (4, quit_but)
global variable (5, loadbut_l)
global variable (6, newbut_l)
global variable (7, optbut_l)
global variable (8, quitbut_l)
global variable (9, loadbut_r)
global variable (10, newbut_r)
global variable (11, optbut_r)
global variable (12, quitbut_r)
global variable (13, chargenwalk_u)
global variable (14, chargenwalk_d)
global variable (15, chargenwalk_l)
global variable (16, chargenwalk_r)
global variable (17, mmenu1)
global variable (18, cmenu1)
global variable (19, cmenu2)
global variable (20, omenu1)
global variable (21, mmenu1slices)
define constant (0, timer:mouse)
#----------------------------------------------------------------------------------------------------
plotscript, new game, begin
suspend player
init mouse
mouse region (-1, -1, -1, -1)
mouse cursor := load walkabout sprite (0)
set variable (mmenu1, on)
set variable (cmenu1, off)
set variable (cmenu2, off)
set variable (omenu1, off)
menu hub
end
#----------------------------------------------------------------------------------------------------
script, menu hub, begin
if (mmenu1 == on) then (mmenu1 create)
if (cmenu1 == on) then (cmenu1 create)
# if (cmenu2 == on) then (cmenu2 create)
# if (omenu1 == on) then (omenu1 create)
end
#----------------------------------------------------------------------------------------------------
script, mmenu1 create, begin
mmenu1slices := create container (320, 200)
load_game := create rect (119, 45)
set parent (load_game, mmenu1slices)
new_game := create rect (113, 45)
set parent (new_game, mmenu1slices)
options := create rect (107, 45)
set parent (options, mmenu1slices)
quit_but := create rect (101, 45)
set parent (quit_but, mmenu1slices)
put slice (load_game, 110, 80)
put slice (new_game, 113, 110)
put slice (options, 116, 140)
put slice (quit_but, 119, 170)
set slice visible (load_game, off)
set slice visible (new_game, off)
set slice visible (options, off)
set slice visible (quit_but, off)
loadbut_l := load large enemy sprite (1)
set parent (loadbut_l, mmenu1slices)
newbut_l := load large enemy sprite (3)
set parent (newbut_l, mmenu1slices)
optbut_l := load large enemy sprite (5)
set parent (optbut_l, mmenu1slices)
quitbut_l := load large enemy sprite (7)
set parent (quitbut_l, mmenu1slices)
loadbut_r := load large enemy sprite (2)
set parent (loadbut_r, mmenu1slices)
newbut_r := load large enemy sprite (4)
set parent (newbut_r, mmenu1slices)
optbut_r := load large enemy sprite (6)
set parent (optbut_r, mmenu1slices)
quitbut_r := load large enemy sprite (8)
set parent (quitbut_r, mmenu1slices)
put slice (loadbut_l, 80, 80)
put slice (newbut_l, 80, 110)
put slice (optbut_l, 80, 140)
put slice (quitbut_l, 80, 170)
put slice (loadbut_r, 160, 80)
put slice (newbut_r, 160, 110)
put slice (optbut_r, 160, 140)
put slice (quitbut_r, 160, 170)
set slice visible (loadbut_l, off)
set slice visible (newbut_l, off)
set slice visible (optbut_l, off)
set slice visible (quitbut_l, off)
set slice visible (loadbut_r, off)
set slice visible (newbut_r, off)
set slice visible (optbut_r, off)
set slice visible (quitbut_r, off)
menu1 loop
end
#----------------------------------------------------------------------------------------------------
script, menu1 loop, begin
set slice x (mouse cursor, mouse pixel x)
set slice y (mouse cursor, mouse pixel y)
if ((slice contains (load_game, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), menu hub)
if ((slice contains (new_game, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), set variable (cmenu1, on), menu hub)
if ((slice contains (options, mouse cursor)) && (mouse button (left button))) then (set variable (mmenu1, off), menu hub)
if ((slice contains (quit_but, mouse cursor)) && (mouse button (left button))) then (game over)
menu1 butbehave
slice to front (mouse cursor)
set timer (timer:mouse, 0, 1, @menu1 loop)
end
#----------------------------------------------------------------------------------------------------
script, menu1 butbehave, begin
set slice visible(loadbut_l, slice contains(load_game, mouse cursor))
set slice visible(loadbut_r, slice contains(load_game, mouse cursor))
set slice visible(newbut_l, slice contains(new_game, mouse cursor))
set slice visible(newbut_r, slice contains(new_game, mouse cursor))
set slice visible(optbut_l, slice contains(options, mouse cursor))
set slice visible(optbut_r, slice contains(options, mouse cursor))
set slice visible(quitbut_l, slice contains(quit_but, mouse cursor))
set slice visible(quitbut_r, slice contains(quit_but, mouse cursor))
end
#----------------------------------------------------------------------------------------------------
script, cmenu1 create, begin
free slice (mmenu1 slices)
use door (0)
end
#----------------------------------------------------------------------------------------------------
Still says the "Slice [x] has been deleted"... Still confused...
By the way; I downloaded the latest nightly as of two weeks ago, and I'd be using it more for my game making, except I constantly get alerts that my games have features that aren't compatible with the nightly. Even if I made them EXCLUSIVELY in the nightly.
J_Taylor wrote:
By the way; I downloaded the latest nightly as of two weeks ago, and I'd be using it more for my game making, except I constantly get alerts that my games have features that aren't compatible with the nightly. Even if I made them EXCLUSIVELY in the nightly.
You should make sure that your copy of game.exe and custom.exe are both from the same nightly. If one is older and the other is newer, you would see error messages like that.
Okay, re-downloaded the nightly, made my slice collection... and now hspeak is saying it's not loading because it doesn't recognize the name as a slice.
Code:
include, plotscr.hsd
include, Alliance.hsi
define constant (0, timer:mouse)
plotscript, new-game, begin
menu1
end
script, menu1, begin
variable (menu1 slice collection, menu1 slices)
menu1 := load slice collection (0)
menu1 slices := lookup slice (Menu1 Slice Holder, menu1 slice collection)
end
script, menu1 buttons, begin
variable (mouse cursor)
init mouse
mouse region (-1, -1, -1, -1)
if (slice contains (Menu1 Button Load, mouse cursor))
then (set slice visible (Menu1 Button LL, Menu1 Button LR))
if (slice contains (Menu1 Button New, mouse cursor))
then (main menu)
if (slice contains (Menu1 Button Options, mouse cursor))
then (main menu)
if (slice contains (Menu1 Button Quit, mouse cursor))
then (quit game)
set timer (timer:mouse 0, 1, @menu1 Buttons)
end
include, Alliance.hsi
define constant (0, timer:mouse)
plotscript, new-game, begin
menu1
end
script, menu1, begin
variable (menu1 slice collection, menu1 slices)
menu1 := load slice collection (0)
menu1 slices := lookup slice (Menu1 Slice Holder, menu1 slice collection)
end
script, menu1 buttons, begin
variable (mouse cursor)
init mouse
mouse region (-1, -1, -1, -1)
if (slice contains (Menu1 Button Load, mouse cursor))
then (set slice visible (Menu1 Button LL, Menu1 Button LR))
if (slice contains (Menu1 Button New, mouse cursor))
then (main menu)
if (slice contains (Menu1 Button Options, mouse cursor))
then (main menu)
if (slice contains (Menu1 Button Quit, mouse cursor))
then (quit game)
set timer (timer:mouse 0, 1, @menu1 Buttons)
end



