Why isn't this code working?

Blitz3D Forums/Blitz3D Programming/Why isn't this code working?

Amanda Dearheart(Posted 2012) [#1]
Ok genuises, why isn't this code working the way I want it to?
Under the Game function, the images are placed on the screen like I want,
But under the Game1 function, when I want the user to click the mouse1 button, the image is supposed to be placed where the mouse cursor is, but no such luck. Anyone care to give me a shot at an answer!




virtlands(Posted 2012) [#2]
Well the code is very complex, and I'd like to help....

I'm curious as to why you're calling the following meshes,
Didn't you mean to say "100 copies of the same image" ?

Your code:
; copy the images that we loaded in LoadGraphics into the Cells array so
; that we can have 100 copies of the same mesh
For x = 1 to 100
Cells(x) = CopyImage(cellY)
Next

I think you'll need to redo the whole thing and try to make it simpler.

I doubt it's necessary to make 100 copies of the same image.
It would probably be better to just use that 1 image and then you can
draw it several times in different positions.

Last edited 2012

Last edited 2012


K(Posted 2012) [#3]
Okay, Miss
Mx = MouseX()
My = MouseY()
Debugcon (Str(Mx), Str(My))
Flip		
If MouseDown(1) Then PlaceImage(Cells(1), Mx, My)   ; Debugcon ("retvalue : " + retvalue$, "max : " + str$(max), "xyl : " + str$(xyl))
Swap the fourth and fifth lines. PlaceImage() is getting called after the backbuffer has already been flipped,so the order never gets sent to the screen.
Regarding what VirtLands said, I would reccomend a 'Image' type, i.e.
Type Image
Field x,y,im
end type

Then your Dim Cells(101) becomes Dim Cells.Image(101).
So then PlaceImage() becomes a function that actually clones a reference to the image rather than the image itself, as in...
;semi-pseudo code
Function PlaceImage.Image(im,x,y)
I.image=New Image
I\im=im
I\x=x
I\y=y
Return I
End Function
;Used like...
Delete Cells(101)
Cells(101)=PlaceImage
;Update to draw
Function DrawCells()
 For k=0to 100
  If Cells(k)<>Null
   DrawImage Cells(k)\im,Cells(k)\x,Cells(k)\y
  Eendif
 Next
End Function
For that matter, the Array could be dispensed with, but that depends on how you want your code to be.


K(Posted 2012) [#4]
Ah, there seems to be more at issue. Errm, first you need to get rid of all those flips, you only really need one, at the end of your loop.
I'll get back to you...
EDIT: Ahah, your DebugCon() func seems to be the culprit, get rid of the viewport stuff,or...move all your DebugCon() calls to after you have drawn your other gfx.

Last edited 2012


Amanda Dearheart(Posted 2012) [#5]
Thanks to all of you for your help guys.
I'll work on them as soon as I get home!

As for the cells topic, that piece of code is only temporary as it was placed there to help me set up a grid section for the game!

It will be dispensed with when the game is completed!


K(Posted 2012) [#6]
In that case, switching to 2d-in-3d would have erased this problem.
Apparently, multiple viewport changes don't agree with blitz's 2d workings, which is a little disappointing... I had always assumed viewport could be used as a sort of scissor.


_PJ_(Posted 2012) [#7]
AFAIK Viewport doesn't crop buffers or anything like that, it simply places a limit on where any 2d draw commands (DrawImage, Text, Circle, Line etc.) content will actually be written to the buffer, As if "placing a template/windoiw over the front of the buffer"


Amanda Dearheart(Posted 2012) [#8]
OK guys, I've updated my code to what I finally really wanted.
I've deleted all references to meshes, removed the grid test block, as I done testing that section of code, changed the 3d angle to 2d, as I couldn't get the 3d version to work the way I wanted.

However the code still doesn't work, witness the code in the SetPattern function



Last edited 2012

Last edited 2012


_PJ_(Posted 2013) [#9]
There's a few issues here.
The "done" variable in the SetPattern function will NEVER become "True" in this loop and therefore the loop will never exit.

You will need something somewhere between Repeat and Forever which can set done to TRUE when the right conditions arise.
Becaus of this, the Main function will never get to run.

Using Rnd(0,1) Will practically NEVER return a 0 or 1 since Rnd returns a floating point value from 0.000000 to 1.0000000 so there's a practically infinite number of values in between!
I recommend using Rand(0,1) if you just want a simple 50/50 chance of Integer 0 or 1 appearing.

Incidentally, you don't need to use SeedRnd every time, just once at the start of the code ought to set the seed for a good randomisation.

I've made a few changes which I hope should help give you a start on fixing the rest of the program.




Amanda Dearheart(Posted 2013) [#10]
Thanks _PJ_

Your input is appreciated, however I have solved the problem to this code about a week ago! but I do appreciate your input!

thanks for the advice about the RND(0,1) suggestion!