|
#1
|
|||
|
|||
|
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 Last edited by nipico; 03-15-2010 at 03:10 PM. |
|
|
|||
|
|
|
#2
|
||||
|
||||
|
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. ^.^ |
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
||||
|
||||
|
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 (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 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 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() 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
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 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
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 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) 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. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
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. ^.^ |
|
#7
|
|||
|
|||
|
yes of course but could you explain in the lua files what is a function
thx |
|
#8
|
||||
|
||||
|
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.
__________________
"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. ^.^ |
|
#9
|
|||
|
|||
|
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 I hope i was clear thx a lot |
|
#10
|
||||
|
||||
|
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. ^.^ |
|
#11
|
|||
|
|||
|
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 |
|
#12
|
|||
|
|||
|
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 |
|
#13
|
||||
|
||||
|
@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. ^.^ |
|
#14
|
|||
|
|||
|
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 |
|
#15
|
||||
|
||||
|
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. ^.^ |
|
#16
|
|||
|
|||
|
ok i will see
for the picture i wrote widht instead of width |
|
#17
|
|||
|
|||
|
How to convert table caracter into a string ?
|
|
#19
|
|||
|
|||
|
thank you for this video
I found it very good!! |
|
#20
|
||||
|
||||
|
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. ^.^ |
![]() |
| Tags |
| pilars earth nipico app |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 01:21 PM.














Linear Mode
