android
  #1  
Old 03-15-2010, 12:30 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default Pilars of the Earth - dev thread

Hello everybody

Nobody answer to my proposition to create this app with me so i decide to make it alone and i create this thread to ask my plenty of questions

First i create a menu where some picture ravel thanks to arrows but sometimes the app is slow and react after two or three click on the arrows. I would like to know why?

thank you in advance
Attached Files
File Type: zip Piliers de la terre.zip (4.97 MB, 149 views)

Last edited by nipico; 03-15-2010 at 03:10 PM.
Reply With Quote

Advertisement [Remove Advertisement]

  #2  
Old 03-15-2010, 12:44 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

First of all, you have a big chunk of your code in the main loop under the "if touch.click(() == 1 then" which isn't really related to the click itself, which means that it will go through that code only right when you click. If that is intentional I'd suggest you put it in a function and call it from there, otherwise, if it's supposed to always check that and it won't cause unwanted changes if it do, then I'd call the function outside of the If-operation.

Also, it would help A LOT with more comments of what the code is doing/supposed to do. You only have headers for the functions mostly, in French to boot. I have a very hard time understanding French, and that would make it hard for me to read your explanations in comments. If you have more comments, and in English, it'd greatly improve our chances of helping.
__________________
"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

  #3  
Old 03-15-2010, 03:04 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

hello i post a new version with comments. I hope they are clear because i'm not perfect in english. if you have other question, ask me.
Reply With Quote

  #4  
Old 03-15-2010, 04:58 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

I'm just going to break up your code and analyze it to see if I've understood it right.
(You don't have to read it all, it's just my analyze. My conclusion is at the end. But I mention some small fixes you could do in the analyze)

Code:
--choix artisans / choose by chance 2 craftsmen cards out of 4 
	math.randomseed(os.time())
	A1=0
	A2=0
	A3=0
	A4=0

	while A1==A2 or A1==A2 or A1==A3 or A1==A4 or A2==A3 or A2==A4 or A3==A4 do
		A1=math.random(4)
		A2=math.random(4)
		A3=math.random(4)
		A4=math.random(4)
	end
Doing this you're generating random numbers (Can cause quite a few iterations since you're randomizing all 4 every time, so they have to by chance return different values for each of them, which can take a while, consider revising) many times until finally A1, A2, A3 and A4 all have a number between 1-4, but not the same. So you get A1=3, A2=1, A3=2, A4=4, for example.
(You have A1==A2 two times in the IF also)

Code:
--choix ressources / choose by chance 7 ressources cards out of 9 (I made 9-7 to be easier)
	R1=0
	R2=0

	while R1==R2 do
	R1=math.random(9)
	R2=math.random(9)
	end
This shouldn't be any problem, should finish quickly. Say you get R1 = 4 and R2 = 8.

Code:
--sélection cartes / 1 the card exists, 0 it does not exist
	--C1 to C4 : the craftsmen cards
	C1=1
	C2=1
	C3=1
	C4=1
	--C5 to C13 : the ressources cards
	C5=1
	C6=1
	C7=1
	C8=1
	C9=1
	C10=1
	C11=1
	C12=1
	C13=1
	if A3==1 or A4==1 then
	C1=0
	end
	if A3==2 or A4==2 then
	C2=0
	end
	if A3==3 or A4==3 then
	C3=0
	end
	if A3==4 or A4==4 then
	C4=0
	end
 	if R1==1 or R2==1 then
	C5=0
	end
	if R1==2 or R2==2 then
	C6=0
	end
	if R1==3 or R2==3 then
	C7=0
	end
	if R1==4 or R2==4 then
	C8=0
	end
	if R1==5 or R2==5 then
	C9=0
	end
	if R1==6 or R2==6 then
	C10=0
	end
	if R1==7 or R2==7 then
	C11=0
	end
	if R1==8 or R2==8 then
	C12=0
	end
	if R1==9 or R2==9 then
	C13=0
	end
Here you set if the card "Exists" or "don't exist". What do you mean by that? If it's a 1, is the card chosen right? And 0 is unused,

With my random numbers these would be:
C1=1
C2=0
C3=1
C4=0

C5=1
C6=1
C7=1
C8=0
C9=1
C10=1
C11=1
C12=0
C13=1

Meaning the "chosen" cards are: C1, C3, C5-7, C9-11 and C13?

Code:
--affichage / post the cards
	screen.orientation(1)
	--ArtEtRes is the background
	ArtEtRes:draw(0,0,height,width)
	screen.update()
Here you draw an image after changing the screen orientation, it's obviously working, but I would change the orientation before saying width=screen.width() and so, just because.

Code:
--Pc is "Première Cartes", it means the first cards who exists
	Pc=0
	while Pc==0 do
		if C1==1 then
		Art11:draw(49,65,140,270)
		screen.update()
		Pc=1
		elseif C2==1 then
        Art12:draw(49,65,140,270)
		screen.update()
		Pc=2
		elseif C3==1 then
        Art13:draw(49,65,140,270)
		screen.update()
		Pc=3
		end
 	end
Here it draws one of the first cards, the craftsman cards. In my made up case it'd be Art11. You skip C4 since there will always be one before that because you've chosen 2 cards of them, right?

Code:
-- I use Tc (1to13) to note the position of the player in the piles of cards
	--But some positions (4 out of 13) the cards don't exist 
	Tc=0
 	if Pc==1 then
 	Tc=1
 	elseif Pc==2 then
 	Tc=2
 	elseif Pc==3 then
 	Tc=3
 	end
Here Tc = 1, since Pc = 1.

Code:
--retour is used to skip a position where there is no cards
	retour=0
 	while 1 do
      if control.read()==1 then
		if control.isTouch()==1 then
			if touch.click()==1 then
			x,y=touch.pos()
			    if x<240  and x>195 and y<228  and y>160 then
			    Tc=Tc+1
			    retour=0
			    elseif x<43  and x>0 and y<228  and y>160 then
			    Tc=Tc-1
			    retour=1
			    end
			    if Tc<=0 then
			    Tc=13
			    retour=1
			    end
				if Tc>=14 then
			    Tc=1
			    retour=0
			    end
Here I don't quite understand what the Retour is doing, but if we take my values and press on the right we get Tc=2 and retour=0.
Code:
				if Tc==1 then
				    if C1==1 then
				    Art11:draw(49,65,140,270)
				    screen.update()
				    elseif C1==0 and retour==0 then
				    Tc=Tc+1
				    elseif C1==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==2 then
				    if C2==1 then
				    Art12:draw(49,65,140,270)
				    screen.update()
				    elseif C2==0 and retour==0 then
				    Tc=Tc+1
				    elseif C2==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==3 then
				    if C3==1 then
				    Art13:draw(49,65,140,270)
				    screen.update()
				    elseif C3==0 and retour==0 then
				    Tc=Tc+1
				    elseif C3==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==4 then
				    if C4==1 then
				    Art14:draw(49,65,140,270)
				    screen.update()
				    elseif C4==0 and retour==0 then
				    Tc=Tc+1
				    elseif C4==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==5 then
				    if C5==1 then
				    S2:draw(49,65,140,270)
				    screen.update()
				    elseif C5==0 and retour==0 then
				    Tc=Tc+1
				    elseif C5==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==6 then
				    if C6==1 then
				    S3:draw(49,65,140,270)
				    screen.update()
				    elseif C6==0 and retour==0 then
				    Tc=Tc+1
				    elseif C6==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==7 then
				    if C7==1 then
				    S4:draw(49,65,140,270)
				    screen.update()
				    elseif C7==0 and retour==0 then
				    Tc=Tc+1
				    elseif C7==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==8 then
				    if C8==1 then
				    F2:draw(49,65,140,270)
				    screen.update()
				    elseif C8==0 and retour==0 then
				    Tc=Tc+1
				    elseif C8==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==9 then
				    if C9==1 then
				    F3:draw(49,65,140,270)
				    screen.update()
				    elseif C9==0 and retour==0 then
				    Tc=Tc+1
				    elseif C9==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==10 then
				    if C10==1 then
				    F4:draw(49,65,140,270)
				    screen.update()
				    elseif C10==0 and retour==0 then
				    Tc=Tc+1
				    elseif C10==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==11 then
				    if C11==1 then
				    P2:draw(49,65,140,270)
				    screen.update()
				    elseif C11==0 and retour==0 then
				    Tc=Tc+1
				    elseif C11==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==12 then
				    if C12==1 then
				    P3:draw(49,65,140,270)
				    screen.update()
				    elseif C12==0 and retour==0 then
				    Tc=Tc+1
				    elseif C12==0 and retour==1 then
				    Tc=Tc-1
					end
				end
				if Tc==13 then
				    if C13==1 then
				    P4:draw(49,65,140,270)
				    screen.update()
				    elseif C13==0 and retour==0 then
				    Tc=Tc+1
				    elseif C13==0 and retour==1 then
				    Tc=Tc-1
					end
				end
			end
After that you have, in the main loop. A lot of IF checks. Are these only supposed to be checked when you click? And should it be possible for more than one to be carried out? If not, I'd make an else if chain, as it is now my values would make this first add Tc+1 in IF Tc==2, making Tc to be 3. That means it triggers the next IF also and draws Art13 (Art13:draw(49,65,140,270)), and updates the screen. (Seems like it should be like this, then no if elseif chain, but I would put it in a separate function and call it in the loop, to tidy it up.)

Code:
elseif control.isButton() ==1 then
			if button.click()==1 then
			ArtEtRes:close()
			Art11:close()
			Art12:close()
			Art13:close()
			Art14:close()
			P2:close()
			P3:close()
			P4:close()
			F2:close()
			F3:close()
			F4:close()
			S2:close()
			S3:close()
			S4:close()
			break
			end
		end
	else
	os.sleep(10)
	end
  end
screen.orientation(0)
Lastly, if the home button is pressed you close resources and break the loop, then change back the orientation. If not you sleep and go to the top.
I'd close the resources once you've exited the main loop, before changing screen orientation. But this way should work too. But you want to keep the main loop tidy to easily see what it's doing.


I can't see how you win the game from the code, or what else you can do other than flip the cards somehow. This isn't the full game, is it?

From what I can gather your problem is that it doesn't react sometimes? For me it always react if I press right, but to the left it doesn't always work.
Pressing left should make the Tc=3 turn to 2, and thus enter Tc==2 and with my values once again lower Tc to 1. Now to enter 1 and draw Art11 since C1=1 it'd have to go back up and check that IF, but it only does that once you press the screen again since this is carried out within the IF touch.click()==1.

The solution to your problem would be to do the check always while the main loop is running. So put it in a function and call it before os.sleep(10) inside that else.
__________________
"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; 03-15-2010 at 05:05 PM.
Reply With Quote

  #5  
Old 03-16-2010, 12:20 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

thx for your answer. indeed it's just the first part of the first part of my game
you're right
I don't know how to reduce the code for the choice of the craftsman

As regards to know if the cards exists you're right with your example

"retour" is use because when you click : Tc=Tc+1 (or -1) and if the card coresponding to the Tc doesn't exist you must repeat Tc=Tc+1 (or -1)

in the main loop i will put an else if chain

finally i understand why it doesn't react at the left but as regards the function I don't what is it. How can i create a function and what should i put in this function

Last edited by nipico; 03-16-2010 at 12:26 PM.
Reply With Quote

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

I could make the change with the function in the code for you and upload it so you can see what I'm talking about. Shall I do that?
__________________
"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

  #7  
Old 03-16-2010, 01:41 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

yes of course but could you explain in the lua files what is a function
thx
Reply With Quote

  #8  
Old 03-16-2010, 03:15 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

There, I added functions to the code and moved where you did the card drawing in the main loop. The problem is still there, but now I can tell you that the problem is in the drawCard() function and has to do with how you handle Tc, and maybe something about the retour variable you use. Go through that code and you may find the problem.
Attached Files
File Type: zip Piliers de la terre.zip (4.97 MB, 21 views)
__________________
"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

  #9  
Old 03-16-2010, 04:09 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

Quote:
Originally Posted by Habhome View Post
The problem is still there.
I found the problem. We should write > and not >= there
Code:
if x<240  and x>195 and y<228  and y>160 then
		Tc=Tc+1
		if Tc>13 then
			Tc=1
		end
		retour=0
	elseif x<43  and x>0 and y<228  and y>160 then
		Tc=Tc-1
		if Tc<1 then
			Tc=13
		end
		retour=1
	end
otherwise it makes a loop because is >=13 too and we used to clik twice to obtain > only
I hope i was clear

thx a lot
Reply With Quote

  #10  
Old 03-17-2010, 11:16 AM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Aha, I see. Glad you found the problem.
And have you understood how you can use function calls now?
__________________
"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

  #11  
Old 03-17-2010, 11:49 AM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

In fact the problem was due to an other thing but i find definitly a solution
Yes i understand how to use functions thank you

ps: congratulation for your black jack

see you
Reply With Quote

  #12  
Old 03-17-2010, 03:12 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

Hello
I've continued in my app but when i want to test it on the simulator the first image doesn't the app block. However i think my code is good.
Could you please look at that thx
Attached Files
File Type: zip Piliers de la terre.zip (4.54 MB, 28 views)
Reply With Quote

  #13  
Old 03-18-2010, 10:33 AM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

@nipico: You're trying to draw your MainMenu.png larger than it is. It is 219x313 pixel, you're trying to draw it as 240x400. You need to resize it to 240x400 for it to work properly.
__________________
"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

  #14  
Old 03-18-2010, 12:15 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

it doesn't solve the problem and moreover i've got some picture which are not in 240*400 but it although work.
Have you got an other idea plz?

And i've got a second question is it possible to ask for name of the player ?

thx
Reply With Quote

  #15  
Old 03-18-2010, 12:55 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Well, I tried changing the code to draw the menu with it's dimension the image had, and then it worked to draw it.

And well, you would need a keyboard in that case and some way of saving the string that it creates. You should look at the note apps to get ideas.
__________________
"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

  #16  
Old 03-18-2010, 01:06 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

ok i will see
for the picture i wrote widht instead of width
Reply With Quote

  #17  
Old 03-18-2010, 02:58 PM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

How to convert table caracter into a string ?
Reply With Quote

  #18  
Old 03-19-2010, 10:29 PM
LordXenos's Avatar
LordXenos LordXenos is offline
Junior Member
 
Join Date: Dec 2009
Location: Louisville, KY, USA
Posts: 94
Default

For those wanting to know how to play the board game:
__________________
If you have a question, please ask. I am more than happy to help.

Cheers,
Your friendly neighborhood
Dark Lord
Reply With Quote

  #19  
Old 03-20-2010, 02:38 AM
nipico nipico is offline
Junior Member
 
Join Date: Feb 2010
Posts: 43
Default

thank you for this video
I found it very good!!
Reply With Quote

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

One thing though, all the gamecards in nipico's game are in French, So I'm afraid not many people will be able to play 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

Reply

Tags
pilars earth nipico app

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 02:24 PM.