Hi everyone, just starting out in purebasic after using blitz based products for the past few years. PureBasic seems very powerfull and intuitive. I was just trying out some simple things to get to grips with the syntax, structure etc. I've hit a small problem which I'm certain is something small and easy to fix to anyone who knows how to code in PB. Anyway this is the code:
What you're into there is the difference between an image number and an image ID. When you draw, you must reference the ID. You are referencing the image number with your code. There are two ways to fix your code:
1. Change:
img = CreateImage(#PB_Any, 100, 100)
to:
img = CreateImage(0, 100, 100)
which will cause img to contain an id instead of an image number and you can leave your drawing code as is
or
1. Leave your CreateImage code as is and change:
DrawImage(img, 10, 10)
to:
DrawImage(UseImage(img), 10, 10)
which will convert the existing image# in the img variable to an id.
The image ID is the handle the OS uses to reference the image, while the image number is something PB alone works with. You will use both items for different purposes, but you must know which it is you're using. When you "hardcode" an image number, like 0 or 34, etc. (a different one for each image) the CreateImage command will return an image ID. (handle) When you use #PB_Any, it will return an image number. The number it returns will be some large value that can resemble an id so it can be confusing.
Welcome to the forums Cammar, if you have any questions while becoming hopelessly hooked on PureBasic, don't hesitate to ask.
Thanks for the quick reply, it's all become so clear now. I guess I'm still used to the blitz way of doing things. I take it the ID/handle thing is universal for all things in purebasic? i.e. sound, gfx etc