
-----------------------------------
J-son
Thu Feb 06, 2014 11:07 pm

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.

 
for k : 1 .. 25
    for p : 1 .. 20
        Mouse.Where (Mx, My, Mb)
        if (((Stat.XC (CurT) * 40 - 20) - (k * 40 - 20)) ** 2) + (((Stat.YC (CurT) * 40 + 80) - (p * 40 + 80)) ** 2)  k * 40 - 40 + PosX and Mx < k * 40 + PosX and My > p * 40 + 60 + PosY and My < p * 40 + 100 + PosY then
                Draw.Box (k * 40 - 40 + PosX, p * 40 + 60 + PosY, k * 40 + PosX, p * 40 + 100 + PosY, 55)
                Draw.Box (k * 40 - 41 + PosX, p * 40 + 59 + PosY, k * 40 + PosX + 1, p * 40 + 101 + PosY, 52)
                if Mb = 1 then
                    for Check : 1 .. FightSize
                        if Stat.Real (Check) = true and Check not= CurT then
                            if k = Stat.XC (CurT) and p = Stat.YC (CurT) then
                                Cancel := true
                                exit
                            end if
                        end if
                    end for
                    Advant (1) := k * 40 - Stat.XC (CurT) * 40
                    Advant (2) := p * 40 - Stat.YC (CurT) * 40
                    for decreasing Shakugan : 10 .. 1
                        Draw.Line (Stat.XC (CurT) * 40 - 20 + PosX, Stat.YC (CurT) * 40 + 80 + PosY, Stat.XC (CurT) * 40 - 20 + (Advant (1) div Shakugan) + PosX,
                            Stat.YC (CurT) *
                            40 + 80 + (Advant (2) div Shakugan) + PosY, 37)
                        Draw.Oval (Stat.XC (CurT) * 40 - 20 + (Advant (1) div Shakugan) + PosX, Stat.YC (CurT) * 40 + 60 + 20 + (Advant (2) div Shakugan) + PosY, 2, 2, 54)
                        View.Update
                        delay (100)
                    end for
                    Stat.XC (CurT) := k
                    Stat.YC (CurT) := p
                    FirstNo := true
                    Moved := true
                    exit
                end if
            end if
        end if
        exit when Moved = true
    end for
    exit when Moved = true
end for


-----------------------------------
Raknarg
Fri Feb 07, 2014 12:56 am

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.

-----------------------------------
DemonWasp
Fri Feb 07, 2014 2:04 am

RE:Mouse.Where is failing to respond
-----------------------------------

    for p : 1 .. 20
        Mouse.Where (Mx, My, Mb)
        

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.

-----------------------------------
J-son
Fri Feb 07, 2014 8:08 am

Re: Mouse.Where is failing to respond
-----------------------------------

for k : 1 .. 25 % For horizontal blocks
    for p : 1 .. 20 % For Vertical Blocks
        Mouse.Where (Mx, My, Mb) % Detect Mouse x,y,b
        if (((Stat.XC (CurT) * 40 - 20) - (k * 40 - 20)) ** 2) + (((Stat.YC (CurT) * 40 + 80) - (p * 40 + 80)) ** 2)  k * 40 - 40 + PosX and Mx < k * 40 + PosX and My > p * 40 + 60 + PosY and My < p * 40 + 100 + PosY then
                % If the mouse is within the Box's radius, then see below.
                Draw.Box (k * 40 - 40 + PosX, p * 40 + 60 + PosY, k * 40 + PosX, p * 40 + 100 + PosY, 55)
                Draw.Box (k * 40 - 41 + PosX, p * 40 + 59 + PosY, k * 40 + PosX + 1, p * 40 + 101 + PosY, 52)
                % Draw another two boxes, different in colour. ^
                if Mb = 1 then
                    % If the mouse is clicked, see below.
                    for Check : 1 .. FightSize
                        % For 1 .. People + Enemies (FightSize) Ids
                        if Stat.Real (Check) = true and Check not= CurT then
                            % If the target exists and the target is not the character moving then
                            if k = Stat.XC (CurT) and p = Stat.YC (CurT) then
                                % If you try to move on top of another person's box then Cancel = true and exit.
                                Cancel := true
                                exit
                            end if
                        end if
                    end for
                    % If the box is free, then proceed
                    Advant (1) := k * 40 - Stat.XC (CurT) * 40
                    Advant (2) := p * 40 - Stat.YC (CurT) * 40
                    % The distance from your new position to your old is Advant
                    for decreasing Shakugan : 10 .. 1
                        % Animation begins
                        Draw.Line (Stat.XC (CurT) * 40 - 20 + PosX, Stat.YC (CurT) * 40 + 80 + PosY, Stat.XC (CurT) * 40 - 20 + (Advant (1) div Shakugan) + PosX,
                            Stat.YC (CurT) *
                            40 + 80 + (Advant (2) div Shakugan) + PosY, 37)
                        Draw.Oval (Stat.XC (CurT) * 40 - 20 + (Advant (1) div Shakugan) + PosX, Stat.YC (CurT) * 40 + 60 + 20 + (Advant (2) div Shakugan) + PosY, 2, 2, 54)
                        View.Update
                        delay (100)
                    end for
                    % Animation ends, if all is successful then New co-ordinates are assigned
                    Stat.XC (CurT) := k
                    Stat.YC (CurT) := p
                    FirstNo := true
                    % ^ This means the person has done an action without ending their turn
                    Moved := true
                    % ^ Moved means they have moved
                    exit
                    % Exit
                end if
            end if
        end if
        exit when Moved = true
    end for
    exit when Moved = true
end for


-----------------------------------
Raknarg
Fri Feb 07, 2014 12:40 pm

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?

-----------------------------------
Zren
Fri Feb 07, 2014 1:01 pm

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.


if (((Stat.XC (CurT) * 40 - 20) - (k * 40 - 20)) ** 2) + (((Stat.YC (CurT) * 40 + 80) - (p * 40 + 80)) ** 2)  Stat.XC (CurT) * 40 - 40 + PosX and Mx < Stat.XC (CurT) * 40 + PosX and Stat.YC (CurT) * 40 + 60 + PosY < My and Stat.YC (CurT) * 40 + 100 + PosY > My then
            Draw.Box (Stat.XC (CurT) * 40 - 40 + PosX, Stat.YC (CurT) * 40 + 60 + PosY, Stat.XC (CurT) * 40 + PosX, Stat.YC (CurT) * 40 + 100 + PosY, 121)
            if Mb = 1 then
                % if char selected
                ClickedChar := true
                SelectChar := CurT
                exit
            end if
        elsif 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 then
            Draw.Box (Stat.XC (T) * 40 - 40 + PosX, Stat.YC (T) * 40 + 60 + PosY, Stat.XC (T) * 40 + PosX, Stat.YC (T) * 40 + 100 + PosY, 121)
            if Mb = 1 then
                % if char selected
                ClickedChar := true
                SelectChar := T
                exit
            end if
        elsif Mb = 1 and Mx > 0 and Mx < 800 and My > 100 and My < 700 then             % If map selected
            Burst := false
            Action := false
            ClickedChar := false
            PosX += Mx - Dx
            PosY += My - Dy
            exit
        end if
    end if
end for


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.

-----------------------------------
Zren
Fri Feb 07, 2014 7:52 pm

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.

Chunk A:

for k : 1 .. 25
    for p : 1 .. 20
        if BattleBlock (k, p) = 1 or BattleBlock (k, p) = 2 then
            Pic.Draw (TileWater, -40 + k * 40 + PosX, 60 + p * 40 + PosY, picCopy)
        elsif BattleBlock (k, p) = 3 or BattleBlock (k, p) = 4 or BattleBlock (k, p) = 5 or BattleBlock (k, p) = 7 then
            Pic.Draw (TileTree, -40 + k * 40 + PosX, 60 + p * 40 + PosY, picCopy)
        elsif BattleBlock (k, p) = 6 then
            Pic.Draw (TileBridge, -40 + k * 40 + PosX, 60 + p * 40 + PosY, picCopy)
        elsif BattleBlock (k, p) = 8 or BattleBlock (k, p) = 9 then
            Pic.Draw (TileFlower, -40 + k * 40 + PosX, 60 + p * 40 + PosY, picCopy)
        elsif BattleBlock (k, p) < 20 then
            Pic.Draw (TileGrass2, -40 + k * 40 + PosX, 60 + p * 40 + PosY, picCopy)
        else
            Pic.Draw (TileGrass, -40 + k * 40 + PosX, 60 + p * 40 + PosY, picCopy)
        end if
    end for
end for



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.


var blockIdToPicId : array 1 .. 3 of int
blockIdToPicId(1) := TileWater % Ocean
blockIdToPicId(2) := TileWater % Lake
blockIdToPicId(3) := TileTree % Forest

var blockId := BattleBlock (k, p)
var picId := blockIdToPicId(blockId)
Pic.Draw (picId, ...)


~~~

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.


% Game Loop
loop
    % Input
    Mouse.Where(...)
    
    % Events
    events() % if mouse.b = 1 then
    
    % Logic
    update() % character(i).position += character(i).velocity
    
    % Draw next frame
    draw() % drawBoard(), drawBrick(), etc

    % FPS Control
    Time.DelaySinceLast(1000 div 60)
end loop


~~~


for T : 1 .. FightSize 
    Mouse.Where (Mx, My, Mb) 


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.

-----------------------------------
J-son
Fri Feb 07, 2014 11:10 pm

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:


for T : 1 .. FightSize
    if Stat.Real (T) = true then             % Detect what is clicked
        if Mx > Stat.XC (CurT) * 40 - 40 + PosX and Mx < Stat.XC (CurT) * 40 + PosX and Stat.YC (CurT) * 40 + 60 + PosY < My and Stat.YC (CurT) * 40 + 100 + PosY > My then
            Draw.Box (Stat.XC (CurT) * 40 - 40 + PosX, Stat.YC (CurT) * 40 + 60 + PosY, Stat.XC (CurT) * 40 + PosX, Stat.YC (CurT) * 40 + 100 + PosY, 35)
            if Mb = 1 then
                % if char selected
                ClickedChar := true
                SelectChar := CurT
                exit
            end if
        elsif 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 then
            Draw.Box (Stat.XC (T) * 40 - 40 + PosX, Stat.YC (T) * 40 + 60 + PosY, Stat.XC (T) * 40 + PosX, Stat.YC (T) * 40 + 100 + PosY, 40)
            if Mb = 1 then
                % if char selected
                ClickedChar := true
                SelectChar := T
                exit
            end if
        elsif Mb = 1 and Mx > 0 and Mx < 800 and My > 100 and My < 700 then             % If map selected
            Draw.Oval (Mx, My, 60, 60, 30)
            Burst := false
            Action := false
            ClickedChar := false
            PosX += Mx - Dx
            PosY += My - Dy
            exit
        end if
    end if
end for


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

-----------------------------------
J-son
Sat Feb 08, 2014 9:37 am

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.

-----------------------------------
J-son
Sat Feb 08, 2014 9:52 am

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:


for T : 1 .. 10
    if Stat.Real (T) = true then             % Detect what is clicked
        if Mx > Stat.XC (CurT) * 40 - 40 + PosX and Mx < Stat.XC (CurT) * 40 + PosX and Stat.YC (CurT) * 40 + 60 + PosY < My and Stat.YC (CurT) * 40 + 100 + PosY > My then
            Draw.Box (Stat.XC (CurT) * 40 - 40 + PosX, Stat.YC (CurT) * 40 + 60 + PosY, Stat.XC (CurT) * 40 + PosX, Stat.YC (CurT) * 40 + 100 + PosY, 35)
            if Mb = 1 then
                % if char selected
                ClickedChar := true
                SelectChar := CurT
                FlipSide := false
                exit
            end if
        elsif 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 then
            Draw.Box (Stat.XC (T) * 40 - 40 + PosX, Stat.YC (T) * 40 + 60 + PosY, Stat.XC (T) * 40 + PosX, Stat.YC (T) * 40 + 100 + PosY, 40)
            if Mb = 1 then
                % if char selected
                ClickedChar := true
                SelectChar := T
                FlipSide := false
                exit
            end if
        elsif Mb = 1 and Mx > 0 and Mx < 800 and My > 100 and My < 700 and MovingInAction = false then             % If map selected
            Draw.Oval (Mx, My, 60, 60, 30)
            ClickedChar := false
            FlipSide := true
        end if
    end if
end for
if FlipSide = true then
    PosX += Mx - Dx
    PosY += My - Dy
    Burst := false
    Action := false
end if


-----------------------------------
Insectoid
Sat Feb 08, 2014 10:58 pm

RE:Mouse.Where is failing to respond
-----------------------------------
Maybe you could find a way to eliminate the for loops entirely.
