April 30, 2024, 12:05:59 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Need HELP with Mystery Mews

Started by whitenite1, September 18, 2010, 09:45:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

whitenite1

Hi all...
  I'm translating a Commodore 64 game into Creative BASIC, and I can't get the program to register the mouse clicks on the second window. After you click on the option 'Interrogate Suspect', the screen will clear and a list of the people appear that are in the room. I now can't get the program to respond to your choice. I'm using an array called routine[x,y] to show if the options are viable, but still nothing.  I hope someone has an idea or two, as I would really like to continue with this game.
  Thanks for any help...

whitenite1

LarryMc

again, after indenting so I could sorta follow your code ;)

in the left button down routine I was trying the name that shows up around line 500 and is associated with element 12 in your routine array.

It appears that when you try to select the person to interrogate the y coordinates are satified in the if statement but the test of the routine array element is not - it is zero

if ((iy > 495) & (iy < 510)) & routine[1,12]=1
at the time that statement is executed (2 places); [1,12] and [2,12]
routine[1,12]=0 and/or  routine[2,12]=0

Without further searching I would say the problem lies with the setting of the routine array elements and/or the calling of the reset subroutine

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Ok, I playedf with it some more.
As I suggested your problem is with the reset.

Your reset subroutine clears ALL of the routine[x,y] elements each time it is called.

In the c3 handler you have this first
if ((iy > 345)&(iy < 360)) & routine[0,2]=1
interrogate
reset
endif

the 1st line is satisfied when you click on interrogate
the 2nd line calls the interrogate sub where a routine[1,x] element is set to 1 (needed in the next step)
the 3rd line resets all of routine back to 0

In the next step you have 12 of these
if ((iy > 330) & (iy < 345)) & routine[1,1]=1
j=1
interrogate_about
reset
    endif

None of them can be satisfied because of the call to reset in the previous step.

Your whole structure is flawed that way; it's not just interrogate.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Quote from: whitenite1 on September 19, 2010, 12:31:12 PM
  You mentioned about indenting. What's the best way to indent the code so others can read it easier, and for me?

I indented your whole program (attached)
In doing so I found duplicate labels and an "endif" with no "if"
Also, you have this line to load the house bitmap:
bldg = LoadImage(getstartpath + "house.jpg",@IMGSCALABLE)
but I don't remember seeing a corresponding
DELETEIMAGE bldg, @IMGSCALABLE
which should be right before you close the windows.

I think that is what is probably causing your program to crash the IDE after running and closing the program a bunch of times.

LarryMc

BTW, the solution for your reset problem may be to simply reverse the order,i.e. reset and then call interrogate.

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

September 25, 2010, 10:01:35 AM #4 Last Edit: September 25, 2010, 10:04:11 AM by Larry McCaughn
attach your current code and I'll look at it real quick before I go take my nap.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

QuoteI have look in the help but all I can find about it is the description of what it does, not how to actually use it in a program.
if i understand you properly you wanna know how work.
simple everything you write under CASE @idlbuttonup
will be executed to next CASE command.
look this simple example:
'main window app
Def w1:window
'create main window
Window w1,0,0,500,400,@minbox,0,"MainGUI",main
Setwindowcolor w1,rgb(220,220,220)
'--------------------------------------------------------
run=1
waituntil w1=0
end
'-------------------------------------------------------
Sub main
Select @class
Case @idclosewindow
closewindow w1
'-----------------------------------------
CASE @idlbuttonup
Move w1,20,20:Print w1,"  UP     "
'-----------------------------------------
CASE @idlbuttondn
Move w1,20,20:Print w1,"DOWN"
'-----------------------------------------

Endselect
Return

LarryMc

I've downloaded your program and will see what I can do.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

whitenite...

Under subrutine :
sub c2messages
' messages for the buildings screen ..

I change @IDLBUTTONDN to @IDLBUTTONUP and it looks that work:
this sub looksnow:

select @CLASS
'******************** there you must use @IDLBUTTONUP *********************
case @IDLBUTTONUP

' the screen co-ordinates where the mouse was clicked ..
ix = @mousex: iy = @mousey
' check whether the mouse click was inside a house circle of
' radius 70px at co-ordinates stored for each house centre point ...
' the equation of the circle is:  (x - xcentre)^2 + (y - ycentre)^2 = radius^2

building = 0 :' no building selected yet ..

for i = 1 to 16
' check for a mouse click within a radius of 65px of the centre of each image ..
if ((ix - house[i,1])^2 + (iy - house[i,2])^2 < 65^2)
' the point is inside a house circle ...
' find which residence corresponds to the ix,iy mouse co-ordinates ...
building = l[58+i]
' exit the for loop ..
i = 16
endif
next i

' show the screen for the selected residence ..
if bldg
showwindow c3,@swrestore
' clear any previous selection message ..
rect c3,0,0,wW,wH,rgb(0,0,60),rgb(0,0,60)
showwindow c2,@swhide
ShowImage c3,bldg,@IMGSCALABLE,(wW - 130)/2,wH*0.1

' describe which residence was selected ...
a$ = "You are at the " + b$[building]+ "."
setfont c3, "Arial",12,700,0
gettextsize c3, a$, textW, textH
move c3,(wW - textW)/2,0.05*wH
frontpen c3, rgb(20,130,255)
drawmode c3,@TRANSPARENT
In-the-building
    endif
endselect
return


Is now work ok?

LarryMc

whitenite

I started to rewrite your program to get rid of ALL the code having to do with mouse locations and involving MOVE and PRINT commands.
That's not saying you are doing it wrong.  I'm just saying that for my style (what I'm use to) your code seems like the long way around things.

Since I don't program using CB I'm not use to the subtle differences between it and IWBasic so I started writing it in IWBasic.

Instead of move and print and showimage I used flatbuttons with the house image and assigned then control IDs of 1-16 inside your loop.  I also assigned all the fonts in a loop.

That way it is real easy to check the control id of a clicked button to see which house was selected.

I was ready to assigned permanent buttons on the selected house screen to hold all the various text entries you move and print.
that way if something is to be shown you use setcontroltext to enter the text and you show the control.  If a buttons value is blank you hide the button.  Again, clicking on a button tells yiu what the user selected.

I didn't go forward with that because I don't know the exact purporse of each of your arrays and don't have the time to try to figure them out.
But I do know that my scheme gets rid of the need for an array to hold house coordinates.
My scheme also creates all the "fields"(buttons) to hold values up front as part of the window creation process.

After that it is simply SETCONTROLTEXT in the proper buttons and responding properly to button clicks.

In the area where you select an activity or a person etc you can use the same button and change what a button click means based upon a mode flag.

Anyway, I'm attaching my skeleton and an exe so you can see what I had done.  Maybe it will give you some ideas.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Had a thought.  Here's why you are getting what you are seeing.

You have your c3messages subroutine.

You test for a buttondown.
You have one big routine that handles all the areas that can be clicked on.
Here's what happens:

the left mouse button is pressed and the program enters the top of the big routine.

it goes through all the if statements until the if that indicates you want to interrogate a person is reached
the x,y says you're ther and the routine array element is 1
the subroutine is called that sets all the routine elements so all the people are listed and it also sets the element for the next step.
that routine then returns to the calling program which is in the 1st section of the big if in c3messages.
the big routine continues to process the big if from the original button press.
the mouse hasn't moved and it reaches the if statement testing to see who you want to talk about.
that if statement is processed and another subroutine is called and the same thing happens again.

Here's what I did.
I changed the buttondn to a buttonup like aurel did.
Then, in each one of the routines that are called in the big if statement I added a RETURN statement.
That makes it so only one of the many little if statements can be called per buttonclick.

Attached is a copy of your program with those changes.

Another possible solution is to change the order of the little if statements:
Right now they  are
routine[1,x]=1
routine[2,x]=1
routine[3,x]=1
routine[4,x]=1
routine[5,x]=1
routine[6,x]=1

to
routine[6,x]=1
routine[5,x]=1
routine[4,x]=1
routine[3,x]=1
routine[2,x]=1
routine[1,x]=1

That way, when a 1,x if is satified; the sub is called and the 2,x values are set, the big if is already pass any if that might be satified.

Anyway, at least you know why it does what it does now.

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Yeah tracer program would be helpful.
Probably simple way will be 'alwaysOntop' window which will read variable values from time to time.
Something similiar i use in ABasic with listbox control.Im just guesing....

WayneA

You can use the "Stop" command to halt program execution at any given point. Once the program has stopped, the debugger will start and allow you to single-step through your program. The Show Variables button can be used to view all program variables and their values at the time.
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

aurelCB

hey thats cool Wayne...
i was wondering why I never use this option.... ::)

LarryMc

It won't run for me because of the error on line 32

Declare "sleep",sleep(nmsec as int),int

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

OK, I searched the forums and found sleep.dll that Graham had posted.

For your program to work you'll have to have that dll in the same folder as your exe or in the windows/system32 folder.

I put the sleep.dll in the same folder as your exe and it ran fine.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library