android
  #21  
Old 03-25-2010, 05:31 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

It was always on the list. Hence why it's on the wiki.
__________________
Only ONE more functions in the Wiki need addressing!
Zen X-Fi2 LUA Wiki
Want to protect your applications? Click Here!
Tower Defense Thread
Zen Lock - Protect Your Zen!
Reply With Quote

Advertisement [Remove Advertisement]

  #22  
Old 03-31-2010, 01:48 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Anyone know of a good way to determine whether a variable is an even or odd number? I think that'd be useful on many ways, I at least need it.
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

  #23  
Old 03-31-2010, 02:05 PM
ZaPx64's Avatar
ZaPx64 ZaPx64 is offline
Member
 
Join Date: Nov 2009
Location: Germany
Posts: 136
Default

You might want to use the modulo operator (%):

Code:
if number % 2 == 1 then
  -- number is odd
else
  -- number is even
end
__________________
Zen X-Fi2 Apps: Notee-fi (notepad) | TicTacToe | Mahjongg
http://www.starfare.eu/ - a free real-time strategy game.
Reply With Quote

  #24  
Old 03-31-2010, 02:08 PM
bzdbbb's Avatar
bzdbbb bzdbbb is offline
X-Fi2 Development Moderator
 
Join Date: Dec 2009
Location: Gloucestershire, UK
Posts: 94
Default

Quote:
Anyone know of a good way to determine whether a variable is an even or odd number? I think that'd be useful on many ways, I at least need it.
This should work;
Code:
 
if n/2 == math.floor(n/2) then
--Its even!
else
--Its odd!
end
EDIT: ZaPx64's way is better, I wasn't aware of the modulo operator.. *goes to add it to Koi Pond*
Reply With Quote

  #25  
Old 03-31-2010, 02:22 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Quote:
Originally Posted by ZaPx64 View Post
You might want to use the modulo operator (%):

Code:
if number % 2 == 1 then
  -- number is odd
else
  -- number is even
end
Thanks. I'm guessing it can also be used to determine if a number is dividable with 3, 4, 5 .. etc?
That's just what I was looking for ^^
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

  #26  
Old 03-31-2010, 04:38 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

In case anyone was wondering: The Modulo operator returns the remainder after the division of the two operands.
__________________
Only ONE more functions in the Wiki need addressing!
Zen X-Fi2 LUA Wiki
Want to protect your applications? Click Here!
Tower Defense Thread
Zen Lock - Protect Your Zen!
Reply With Quote

  #27  
Old 03-31-2010, 05:26 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Quote:
Originally Posted by ThievingSix View Post
In case anyone was wondering: The Modulo operator returns the remainder after the division of the two operands.
So 10%4 returns the value 0,5? And 8%5 returns 0,6? Have I understood it right then?
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

  #28  
Old 03-31-2010, 07:51 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

10 mod 4 returns 2. 8 mod 5 returns 3.

Image attached, in paint lol:
__________________
Only ONE more functions in the Wiki need addressing!
Zen X-Fi2 LUA Wiki
Want to protect your applications? Click Here!
Tower Defense Thread
Zen Lock - Protect Your Zen!
Reply With Quote

  #29  
Old 04-01-2010, 01:28 AM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Quote:
Originally Posted by ThievingSix View Post
10 mod 4 returns 2. 8 mod 5 returns 3.

Image attached, in paint lol:
Oh I see. Now I get it. Though I'm not very good with that method of division, I use it way too little to remember it xD
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

  #30  
Old 05-03-2010, 02:29 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Since apps are beginning to become quite image heavy and the load time for some things have become noticeable I have created a general loading screen code which displays a custom message, it works with any orientation since it loads the screen height and width every time it's called:

Code:
--Draw loading screen
function loadingScreen(msg)
	colorW = color.new(255,255,255)	--Creates the color white
	colorB = color.new(0,0,0,192)		--Creates the color black, alpha 192 (75%)
	shgt = screen.height()		--Saves a variable with the screen height
	swdt = screen.width()		--Saves a variable with the screen width
	text.size(20)		--Set text size to 20 pixel
	text.color(colorW)	--Set text color to white
	screen.fillrect(0,0,swdt,shgt,colorB)	--Fill screen with black
	text.draw(0,shgt/2-10,msg,"center",swdt)	--Draw your message in the center
	screen.update()	--Draw image buffer to screen
end

loadingScreen("Loading Game...")	--Loadfunction is called with a message in quotes which will be displayed
You have the declaration of the function before any function calls you make so it may have to be above all your image loads even.
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^

Last edited by Habhome; 05-09-2010 at 06:10 AM.
Reply With Quote

  #31  
Old 05-04-2010, 09:32 AM
ZaPx64's Avatar
ZaPx64 ZaPx64 is offline
Member
 
Join Date: Nov 2009
Location: Germany
Posts: 136
Default

Haha, nice one, I created one as well for my project yesterday Quite useful indeed.
__________________
Zen X-Fi2 Apps: Notee-fi (notepad) | TicTacToe | Mahjongg
http://www.starfare.eu/ - a free real-time strategy game.
Reply With Quote

  #32  
Old 05-04-2010, 09:43 AM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Quote:
Originally Posted by ZaPx64 View Post
Haha, nice one, I created one as well for my project yesterday Quite useful indeed.
Cool, yeah I noticed that I needed it once more, so I just modified the one I used in Black Jack to become a very simple universal one =P Does your's differ much from mine? Always interesting to see different solutions ^^
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

  #33  
Old 05-05-2010, 08:32 AM
ZaPx64's Avatar
ZaPx64 ZaPx64 is offline
Member
 
Join Date: Nov 2009
Location: Germany
Posts: 136
Default

It's not universal and it requires an external (sandclock) image which is shown up instead of text, but it's the same at all. Uh, and the background is black with 75% transparency, maybe you can try that out as well, looks a bit more fancy. :P
The image needs to be closed at the end of the program and takes some memory during the runtime so I guess your one is the best solution.
__________________
Zen X-Fi2 Apps: Notee-fi (notepad) | TicTacToe | Mahjongg
http://www.starfare.eu/ - a free real-time strategy game.
Reply With Quote

  #34  
Old 05-05-2010, 11:08 AM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Quote:
Originally Posted by ZaPx64 View Post
It's not universal and it requires an external (sandclock) image which is shown up instead of text, but it's the same at all. Uh, and the background is black with 75% transparency, maybe you can try that out as well, looks a bit more fancy. :P
The image needs to be closed at the end of the program and takes some memory during the runtime so I guess your one is the best solution.
Yeah, I thought about transparency, but I was too lazy to calculate a good amount for it =P Which value do you use? I can put it into the fragment above ^^
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

  #35  
Old 05-05-2010, 04:19 PM
ZaPx64's Avatar
ZaPx64 ZaPx64 is offline
Member
 
Join Date: Nov 2009
Location: Germany
Posts: 136
Default

I use currently 50 which is quite decent, 128 and 192 work good as well.
__________________
Zen X-Fi2 Apps: Notee-fi (notepad) | TicTacToe | Mahjongg
http://www.starfare.eu/ - a free real-time strategy game.
Reply With Quote

  #36  
Old 05-07-2010, 10:49 AM
Brett_val's Avatar
Brett_val Brett_val is offline
Senior Member
 
Join Date: Jan 2010
Location: The Netherlands
Posts: 636
Default Volume control

Here is a code to add volume control to any app. It sets the volume when you click on it, and you can also scroll it.
It's almost universal and works pretty well so I thought I'd post it here.

You may have to change the colors if it doesn't fit your app well, or you can add some graphics to it..
I couldn't find a way to save the text.color the app is using (to temporarily change it and set it back at the end), so it uses the same text.color as set in the app. If you want another text.color for the volume control you can change the text.color at the start of function volume(), and change it back at the end of it.

If you have any problems adding this to your code, pm me and I'll try to help you out.

Copy paste this function:
Code:
function volume()
	local oldsize=text.size(16)		--save text size to set it back later, and for now use size 16
	local sheight=screen.height()	--get the current screen height (depends on screen orientation)
	local swidth=screen.width()		--get the current screen width (depends on screen orientation)
	
	while 1 do
	
		screen.fillrect(swidth-30,sheight-220,30,210,color.new(0,0,0))																--black background
		text.draw(swidth-27,sheight-218,audio.volume(),"center")																	--text.draw current volume level
		screen.drawrect(swidth-20,sheight-201,swidth-10,sheight-20,color.new(255,255,255)) 											--frame of volume bar
		screen.fillrect(swidth-18,(sheight-200)+(180-(180*(audio.volume()/25))),7,180*(audio.volume()/25),color.new(155,155,155)) 	--volume bar
		screen.update()
		
		if control.read(1) then
			if control.isButton()==1 and button.event()==1 then
				break														--use home button click to end this function
			elseif control.isTouch()==1 then
				touch_x,touch_y=touch.pos()
				if touch.event()==2 then 									-- =touch.down
					if touch_x>=(swidth-30) and touch_y>=(sheight-220) then		--if you touched somewhere in the volume control window
						if touch_y>=(sheight-200) and touch_y<=(sheight-20) then	--if you touched within the frame of the volume bar,
							audio.volume(math.floor(((touch_y-(sheight-20))/7)*-1))		--calculate where you touched and set the volume at that level
						elseif touch_y<(sheight-200) then							--if you touched just above the volume bar, 
							audio.volume(25)											--set volume to 25
						elseif touch_y>(sheight-20) then 							-- if you touched just below the volume bar, 
							audio.volume(0)												--set volume to 0
						end
					end
				elseif touch.event()==4 then								-- =touch.click
					if touch_x<swidth-30 or touch_y<sheight-220 then			--if you clicked outside the volume control window,
						break														--end this function
					else
						audio.beep(440,100)										--after tapping the volume bar, play beep (or replace this with a nice sound)
					end
				elseif touch.event()==32 and touch_x>=(swidth-30) and touch_y>sheight-200 and touch_y<sheight-20 then	--if you moved within the frame of the volume bar
					audio.volume((math.floor((touch_y-(sheight-200))/7)-25)*-1)	--calculate the position where you are moving, and set the volume at that level
					for i=0, 50 do
						control.read()												--clear queque for smooth movements
					end
				elseif touch.event()==1 then								-- =touch.up
					audio.beep(440,100)											--after scrolling the volume bar, play beep (or replace this with a nice sound)
				end
			end
		end
	
	end
	text.size(oldsize)				--set text size back at what it was before
									--If your game doesn't refresh the screen automatically, place something like "drawgame()" here
end
and modify your control.isButton() checks so it looks something like this:
Code:
if control.isButton()==1 then
			if button.event()==16 then	-- =button.hold
				volume()
			elseif button.event()==1 then	-- =button.click
				break
			end
Attached Images
File Type: png volume_sh.png (7.0 KB, 26 views)
Reply With Quote

  #37  
Old 11-01-2010, 12:00 PM
Redwolfhome's Avatar
Redwolfhome Redwolfhome is offline
Junior Member
 
Join Date: Mar 2010
Location: Germany
Posts: 91
Default

Her is my preloader with processbar:
load2.pngload1.png
Code:
function preload() new_proc = proc + resadd;preheight = height/4*3+41-(new_proc*2-12);screen.fillrect(width/4,preheight,width/4*2,new_proc*2-12,black);screen.update();return new_proc;end;
You have to add the function on the top of your file. Than you have to put ther this code:
Code:
height = screen.height()
width= screen.width()
white = color.new(255,255,255);
black = color.new(0,0,0);
screen.fillrect(0,0,width,height,white);
text.size(30);
text.color(black);
screen.drawrect(width/4,height/6*2+20,width/4*3,height/4*3+40,black);
text.draw(0,height/6+20,"Load","center",width);
screen.update();
resadd = 100/5+1;--you have to replace the 5 with the number of your files which you want to load an this number
proc = resadd;
screen.update();
And then you have to load your images and songs...
Code:
highscoreslogo_img = image.load("gfx/highscoreslogo.png");proc=preload();
howtobtn_img = image.load("gfx/howtobtn.png");proc=preload();
logo_img = image.load("gfx/logo.png");proc=preload();
And then this code:
Code:
screen.fillrect(0,0,width,height,white);
text.size(30);
text.color(black);
screen.drawrect(width/4,height/6*2+20,width/4*3,height/4*3+40,black);
screen.fillrect(width/4,height/6*2+20,width/4*2,proc*2-12,black);
text.draw(0,height/6+20,"Finish","center",width);
screen.update();
os.wait(600);
This code works well with both kinds of orientation! Just add
Code:
screen.orientation(1);
before
Code:
height = screen.height()
width= screen.width()
Reply With Quote

  #38  
Old 12-12-2010, 11:52 AM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

Code:
This isnt really a function snippit but the formats for os.date()



%a = abbreviated weekday names (ie:Wed)
%A = full weekday names(ie: Wednesday)
%b = abbreviated month names (ie:Dec)
%B = full month names (ie:December)
%c = date and time (ie: 09/16/98 23:48:10)
%d = day of the month(ie:16)
%H = hour in 24hour clock
%I = hour in 12hour clock
%M = minutes(ie:48)
%m =month(i:9)
%p = either am or pm
%s = seconds(ie:10)
%w = weekday(ie:3)
%x = date (ie: 09/16/98)
%X = time(ie: 23:48:10)
%Y = full year(ie:1998)
%y = two digit year(ie:98)
 %% = the character %
Reply With Quote

  #39  
Old 01-30-2011, 01:37 PM
Redwolfhome's Avatar
Redwolfhome Redwolfhome is offline
Junior Member
 
Join Date: Mar 2010
Location: Germany
Posts: 91
Default

Ok this isnīt really a code fragment but its a tip:
If you draw an image with the screen.fillrect memory it takes more memory thanusing an compremize image:
I have tested it with an rectangle in black...
Reply With Quote

  #40  
Old 01-30-2011, 03:17 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Quote:
Originally Posted by Redwolfhome View Post
Ok this isnīt really a code fragment but its a tip:
If you draw an image with the screen.fillrect memory it takes more memory thanusing an compremize image:
I have tested it with an rectangle in black...
So redrawing a 240*400 image takes less than a 240*400 filled square? Sounds odd... Might only be applicable for one colored stuff, had lots of trouble with redrawing to get it smooth in my Paradise Slots where I use images. Though, I use several layers of them..
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 08:14 AM.