|
Problem with keys |
Allfreeware
Member #8,435
March 2007
|
Hi all.4 days ago i've begin to program a fight game.
xsel=this's for cech what caracter is now "selected" Where's the problem? |
Onewing
Member #6,152
August 2005
|
Quote: Where's the problem? I don't think it's in the code you posted, unless imgsel or buf is messed up somehow. Just because you press left or right causes a crash doesn't mean that the problem is right there. Have you tried figuring out exactly where it crashes using a debugger? ------------ |
Allfreeware
Member #8,435
March 2007
|
You've reason.The problem is the bmp,i've save it at 8 color and so allegro haven't read it. |
Kris Asick
Member #1,424
July 2001
|
You should show us the code where imgsel is updated. Crashes are usually related to drawing null BITMAP objects, or drawing objects which aren't BITMAPs. Also, please tell us if you're using datafiles or not. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Allfreeware
Member #8,435
March 2007
|
Now i've resolve the problem with this code,but now the img remain in the screen at the first player and i can't move it...:o
Thanks |
bamccaig
Member #7,536
July 2006
|
Allfreeware said: if(finetutto=1) I'm assuming the above variable is an integer. The equals sign (=) is an assignment operator (unless you've overloaded it, but it's impossible to tell from the code you've given), which means that you assign 1 to finetutto and evaluate it as a boolean conditional. Allfreeware said: if(xsel=1) Same thing here. I'm pretty sure the above statements will always be true. To check if a value is equal to another one make sure you use the comparison operator (==). Perhaps you manually entered the code and forgot an equals sign? This is where copy/paste is your friend: it's faster and it makes sure we see the exact code you're having problems with. It might also help to see a more complete picture (i.e. show more or all of the code). In the case of xsel, you then go on to check if it equals 2, 3, 4, and 5. Unless it is being changed in a separate thread you should know as soon as the first is true that the others have to be false. For this reason, it appears that you should be using an else...if ladder:
Or even cleaner is a switch statement:
Note that an else...if ladder or switch statement are only applicable if xsel doesn't change during these checks. Sorry, I assume English isn't your first language? I'm having trouble understanding... It would help if you posted all the code (assuming it's not too much) and any error messages would also help. Perhaps if you run from the command-line you will get text output from Allegro? Try to explain what each block of code does with comments. Especially try to explain what each variable represents and what type it is. More descriptive variable names would also help. Also, there doesn't seem to be anything that prevents xsel from going below 1 or above 5. If it's out of range should it be moved back into range or do you just want to ignore it?? -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Allfreeware
Member #8,435
March 2007
|
Wow!Really Really thanks for the help.
And now the menĂ¹ work fine;) |
Neil Black
Member #7,867
October 2006
|
bamccaig said: Also, there doesn't seem to be anything that prevents xsel from going below 1 or above 5. If it's out of range should it be moved back into range or do you just want to ignore it??
Allfreeware said:
if (xsel<=xlimdes) and... Allfreeware said:
if(xsel>=xlimdes) Those prevent it from going out of range.
|
bamccaig
Member #7,536
July 2006
|
Possumdude0 said: Those prevent it from going out of range. Guess I missed that... If you ask me the check should be applied inside the function that accesses the variable. Those functions could be called elsewhere and if you forget to implement the check you could again go out of range. On top of that, if you implement the check in the increment/decrement functions it would eliminate a redundant check before calling the function (assuming the function could at some point be called elsewhere).
It would also clean up the game logic a bit.
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
|