Computer Science Canada Mouse.Where is failing to respond |
Author: | J-son [ Thu Feb 06, 2014 11:07 pm ] | ||
Post subject: | Mouse.Where is failing to respond | ||
Alright. I am using a for loop, and Mouse.Where after the for to read the Mouse's button. When the button goes down, my code is to advance. However, only RARELY does pressing the mouse actually work. Most of the time there is no response. I had my code working earlier- I changed a few variables prior to this for loop, but I doubt they have any impact on this.
|
Author: | Raknarg [ Fri Feb 07, 2014 12:56 am ] |
Post subject: | RE:Mouse.Where is failing to respond |
Without context this code is really just not making sense to me. If you want a better response (if no one else if able to help you right now), upload the whole code, and document your code so we know what the block is supposed to be doing. |
Author: | DemonWasp [ Fri Feb 07, 2014 2:04 am ] | ||
Post subject: | RE:Mouse.Where is failing to respond | ||
If you pause for a full second in between calls to Mouse.Where, it's easily possible to miss entire clicks. You need to avoid having too many long delays between each call to Mouse.Where. |
Author: | J-son [ Fri Feb 07, 2014 8:08 am ] | ||
Post subject: | Re: Mouse.Where is failing to respond | ||
|
Author: | Raknarg [ Fri Feb 07, 2014 12:40 pm ] |
Post subject: | RE:Mouse.Where is failing to respond |
Oh good call, DemonWasp. He's right, if your delays are too long, it won't even register your mouse. Usually if you ahve a delay it's only for a few milliseconds. Why's yours so long? |
Author: | Zren [ Fri Feb 07, 2014 1:01 pm ] | ||||||||||
Post subject: | RE:Mouse.Where is failing to respond | ||||||||||
Some things that make your code easier to read: When doing a long calculation, break it up and put it the parts on their own line and assign it to a variable. This way you can use descriptive variable names to make the code more readable.
I'm guessing Stat is a record. XY and YC are the center of the blocks? What does the number 40 represent? What about 80? 20? You have a LOT of "Magic Numbers" that represent some transformation on the coordinates, but you haven't described them. Assign the value to a variable if you ever use a number more than once. You ought to be assigning it to a variable. That way you only have to change it in one spot should you ever need to. Even if you only use it once, using a descriptive variable name will make the code more readable than a number the reader has to guess at.
I'm guessing 40, 20 and 80 all have something in common, or are based on 40?
|
Author: | J-son [ Fri Feb 07, 2014 3:38 pm ] |
Post subject: | Re: Mouse.Where is failing to respond |
I didn't think I would need to post other parts of my code, I needed to know why the Mouse did not respond. For the delay: If the mouse is pressed, then it moves into the animation. The animation needs the delay so the user can see the character moving. So: for decreasing Shakugan : 10 .. 1, draw the line, delay, draw the line a bit further, and so on. When the animation is finished, a variable is called to true and then the loop is exited. After this, the character cannot be moved until they leave their turn. My problem is: I cannot get the Mouse click to activate. With no clicks, there will be no animation. No animation means no delay. My other problem is: This code worked previously. I then added a second character into the controls, and now clicking rarely works. Background info: I am making a game - a turn based RPG, similar to Tactics ogre, Grimoire of the rift etc.. Except the map is 2d, so each 'block' or 'tile' is 40x40. The 20 and 80 is to get into the middle of the block, so I can judge distances of the character. E.G - If the character has 3 'burst,' the character can go to a block with its middle 120 away from his current tile's middle. Vars: Stat := Person's stats, Type Records - XC,YC: - X-Coordinate, Y-Coordinate Burst: Similar to move CurT: Current Target Advant, Shakugan: Animation vars, not much use FightSize: Determines the amount of players of both sides Mb: Mouse button Moved: Determines whether the player has used up his/her Movement for his turn So- I've placed a delay before the [if Mb = 1 then] and after it. If works for the before, which means it gets to that code. After the code, however, no reaction. I still can't find out why |
Author: | evildaddy911 [ Fri Feb 07, 2014 4:15 pm ] |
Post subject: | RE:Mouse.Where is failing to respond |
there could be 2 reasons for that. one would be its not running the mouse.where line, another could be a second delay somewhere else. question: is this section of your code within another loop? otherwise it could easily be doing the 25*20=500 iterations, then continuing. looking at the code, if the mouse is not pressed in time, the 500 iterations could be over in under 10 milliseconds if you have a decent computer If it is already inside an infinite loop, then you need to check for any other delays that could be causing it to miss the click |
Author: | J-son [ Fri Feb 07, 2014 4:43 pm ] |
Post subject: | Re: Mouse.Where is failing to respond |
I only have 2 delays - One for buttons in the "Action" section, which does not run if movement is being run, and the movement animation. My laptop is a gaming laptop, Top of the line (MSI GS70) It is in an infinite loop, with boolean vars causing lines to run or not. I ran my file again, the char moved twice then once again not reponding Edit: I've done more testing .. may have the problem strangled in a bit |
Author: | J-son [ Fri Feb 07, 2014 5:43 pm ] | ||||
Post subject: | Re: Mouse.Where is failing to respond | ||||
I've found the problem; it appears to be 2 sections of code that conflict. Prior to my original posted code, where these 2 chunks. Chunk A:
Chunk B
The problem: If Chunk A is on top of Chunk B, Moving works, but the enemies cannot be selected. Edit: Highlighting fails here If Chunk B is on top of Chunk A, Moving fails but enemies can be selected. Edit: Enemies are highlighted, but cannot be selected Still a problem with the mouse either way. I do not see a correlation between the Chunks of code, but obvious there is. |
Author: | Zren [ Fri Feb 07, 2014 7:52 pm ] | ||||||||
Post subject: | Re: Mouse.Where is failing to respond | ||||||||
Tip: Whenever you have extremely similar code, there's likely tools to simplify things. Take Chunk A for example. J-son @ Fri Feb 07, 2014 5:43 pm wrote: Chunk A:
The only difference in most of those if statements is the picId you're going to draw, and the blockId you use to select which picId. You can map blockIds to picIds with an array.
~~~ Quote: If Chunk A is on top of Chunk B, Moving works, but the enemies cannot be selected
All chunk A does is draw things. Chunk B has logic code AND drawing code intermingled. Try to break apart the logic from the drawing code.
~~~
Why are you updating the mouse variables FightSize number of times every game loop? ~~~ The only common thing between the two pieces of code that I can see is that you change PosX and PosY in Chunk B, and Chunk A references it. |
Author: | J-son [ Fri Feb 07, 2014 11:10 pm ] | ||
Post subject: | Re: Mouse.Where is failing to respond | ||
I attempted to separate the code, where Draw used to be was then LogicFix (k) However, Highlighting stopped working, and so enemies still could not be accessed. I've noticed that clicking is slower or inaccurate when the Mouse.Where is not in the for loops. So I put it after every for loop I have that used the mouse. Enemy clicking still fails to respond, movement is fixed. I've gone closer to the problem:
The enemy's Stat.Real is true. So, the if statement is passed, and proceeds to the next if. Now, the first if determines if it is the character's whose turn it is, is highlighted. The second elsif is for any character who is waiting.. enemies fall in this category. The last determines if no character is clicked but the map is. My problem now- when I click on the enemy, it goes straight to the last elsif This means the previous elsif is not true. How so? Mx > Stat.XC (T) * 40 - 40 + PosX and Mx < Stat.XC (T) * 40 + PosX and Stat.YC (T) * 40 + 60 + PosY < My and Stat.YC (T) * 40 + 100 + PosY > My Let's say Mx = 100, My = 200 PosX and PosY = 0 Stat.XC = 3,Stat.YC = 3 (Actual coordinates) So 100 > 80 and 100 < 120 and 180 < 200 and 220 > 200 It should work |
Author: | J-son [ Sat Feb 08, 2014 9:37 am ] |
Post subject: | Re: Mouse.Where is failing to respond |
I've narrowed the possibilities down further: It appears the for loop is the cause. It goes from the character 1 .. FightSize (12) Char 1 is the main character, 10 being the target I am using. So, in the first for loop, if Mouse.Click = 1 then it will go to the last elsif and exit. This causes no targeting. Only problem now is my 'Moving' is having hiccups. It's working 70% of the time, it may be a for loop problem too. |
Author: | J-son [ Sat Feb 08, 2014 9:52 am ] | ||
Post subject: | Re: Mouse.Where is failing to respond | ||
It appears that for loop had caused all problems. Through more tests, it appears when I click for a location to move - It goes through that loop first, and counts the 'Move' as an outlier click. There, it cancels the 'Move' boolean and therefore cancels the 'Move.' Future reference of new code:
|
Author: | Insectoid [ Sat Feb 08, 2014 10:58 pm ] |
Post subject: | RE:Mouse.Where is failing to respond |
Maybe you could find a way to eliminate the for loops entirely. |