Custom Menu System

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting. You may Image to help finance the hosting costs of this forum.
Post Reply
User avatar
Kesa
Journeyman
Posts: 67
Joined: Fri Sep 10, 2010 11:44 pm

Custom Menu System

Post by Kesa »

ok here it is my attempt at something crazy for one so noob as me.

I am making a custom menu for a custom dungeon, duh lol. Well the system works and all, except the cancel button jumps around a lot from one menu to the next when it shouldnt.

Image

This menu works great when it starts out. Yep its perfect!!! Then when you hit start it takes you to the image below.

Image

Now this also works perfectly, and cancel takes you back to the above title screen, then things get messed up.
After you return to the title screen exit takes you BACK to...image below...wtf

Image

Then cancel takes you back to title screen as it should, it can do this for some time before it FINALLY EXITS the game... o.0 none of the other menus have this problem that I have seen yet, so here is all the code, which might be a lot and could be partially copy and paste, but wth who cares it works right? Well most of it works.

Code: Select all

function front_door_draw(bmp, mx, my)
	dsb_bitmap_draw(gfx.title, bmp, 0, 0, false)
	
end
function start_menu_draw(bmp, mx, my)
	dsb_bitmap_draw(gfx.start_menu, bmp, 0, 0, false)
end
function chara_build_draw(bmp, mx, my)
	dsb_bitmap_draw(gfx.select_menu, bmp, 0, 0, false)
end
function front_door_click(x, y, b)
	if (b == 1) then
	    if (x > 20 and x < 157) then
	        if (y > 248 and y < 287) then
	        	dsb_sound(snd.click)
			local v = dsb_fullscreen(start_menu_draw, start_menu_click, nil, true)
			return v			
		end
	     end
	        if (x > 20 and x < 231) then
			if (y > 305 and y < 344) then
	           	    if (gt_savegames > 0) then
	             		   dsb_sound(snd.click)
	              		   return 1
			    end
			end
		end
--exit button
	       	if (x > 20 and x < 112) then
			if (y > 359 and y < 397) then
				dsb_sound(snd.click)   
				return 2
			end
		end
	 end
	
end

function start_menu_click(x, y, b)
	if (b == 1) then
	    if (x > 58 and x < 313) then
	        if (y > 123 and y < 183) then
	        	dsb_sound(snd.click)
			local v = dsb_fullscreen(chara_build_draw, chara_build_click, nil, true)
			return v
					
		end
	     end
	        
		 if (y > 207 and y < 270) then
	           	 dsb_sound(snd.click)
	              	 return 0
			
		 end
		
--cancel button	    	 
		if (y > 290 and y < 356) then
			dsb_sound(snd.click)
			local v = dsb_fullscreen(front_door_draw, front_door_click, nil, true)
			return v
		end
			
	 end
	return nil
end
function chara_build_click(x, y, b)
	if (b == 1) then
	    if (x > 97 and x < 167) then
	        if (y > 115 and y < 179) then
	        	dsb_sound(snd.click)
			
					
		end
	     end
	         if (x > 97 and x < 167) then
		     if (y > 212 and y < 274) then
	           	 dsb_sound(snd.click)
	              	 
			
		     end
		 end
	       	if (x > 187 and x < 209) then	 
		     if (y > 115 and y < 179) then
			dsb_sound(snd.click)
			
		     end
		end
		if (x > 187 and x < 209) then	 
		     if (y > 211 and y < 275) then
			dsb_sound(snd.click)
			
		     end
		end
--cancel button
		if (x > 48 and x < 308) then	 
		     if (y > 358 and y < 430) then
			dsb_sound(snd.click)
			local v = dsb_fullscreen(start_menu_draw, start_menu_click, nil, true)
			return v
		     end
		end		
	 end
	return nil
end

function front_door(savegames)
	gt_doorstate = 0
	gt_savegames = savegames
	local v = dsb_fullscreen(front_door_draw, front_door_click, nil, true)
	if (v == 999) then
	    gt_door_opening = true
	    return (dsb_fullscreen(front_door_draw, nil, nil, false))
	else
		return v
	end
	
end
That's all of it, please help me figure fix this problem of back and forth exit button when it should exit everytime at the title screen not only at the start.
Last edited by Kesa on Mon Apr 18, 2011 3:13 am, edited 1 time in total.
User avatar
Sophia
Concise and Honest
Posts: 4307
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Custom Menu System

Post by Sophia »

I'm actually not sure what you're trying to do. A lot of that code is related to animating the opening door, which both blocks of code don't need... I don't think? Honestly, it looks like you cut and pasted a huge chunk of it without really reading through it, because I can't really make sense of it. Whatever editor you used messed up the indenting, which doesn't help, either.

I'd suggest you go through the basic version line by line and really understand it, and then only copy and paste what you need, rather than trying to adapt a huge block of code that may not even suit your purposes at all. It will be slower going but in the long run you'll learn a lot more and have a lot less problems.
User avatar
cowsmanaut
Moo Master
Posts: 4380
Joined: Fri Jun 30, 2000 12:53 am
Location: canada

Re: Custom Menu System

Post by cowsmanaut »

I'm a copy and paste coder too. I think most artists are. However, Sophia is right, it's better to copy paste small sections, discover what they do and then even comment them yourself so you know when you come back to it what it did and how you changed it. It'll also help others when they need to help you. Code can be a big tangled mess very fast, especially if you're not sure what any of it does, and eventually can't remember what you changed. I have to do scripted events for work all the time.. and I hate them, and never remember what they do from year to year.. so the excessive commenting makes my life much easier!

hang in there, it'll get easier with time.. I promise :D
User avatar
Kesa
Journeyman
Posts: 67
Joined: Fri Sep 10, 2010 11:44 pm

Re: Custom Menu System

Post by Kesa »

BUMP

Ok I redid my 1st post on the problem in hopes of a fix. Hopefully I explained and gave enough visual for this to get resolved cause I seem to be unable to figure out why out of all the code only exit is effected by it...
User avatar
Kesa
Journeyman
Posts: 67
Joined: Fri Sep 10, 2010 11:44 pm

Re: Custom Menu System

Post by Kesa »

Hmmm suddenly it works fine...What a weird day for me
Post Reply