Are Sprite id's global or local

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by duschman.

Hi,

I do my first steps with the demo of Purebasic to find out if it
fits my requirements. I tried to play around with a game idea.
So I need a counter which runs in the background.
The filenames for the digits are count0-count9.bmp in the \images folder.

Procedure initCounter()
CreateSprite(20,18,22,0)
CreateSprite(21,18,22,0)
CreateSprite(22,18,22,0)
CreateSprite(23,18,22,0)

For i = 0 To 9
filename.s = "images\count" + Str(i) + ".bmp"
LoadSprite(i,filename,0)
Next
EndProcedure

That works fine. now I have the Counter Procedure

Procedure SetCounter()
timecount = 1440
While timecount > 0
counter.s = Str(timecount)
;counter.s = LSet(counter,3,"0")
count1 = Val(Mid(counter,1,1))
count2 = Val(Mid(counter,2,1))
count3 = Val(Mid(counter,3,1))
count4 = Val(Mid(counter,4,1))

CopySprite(count1,20,0)
CopySprite(count2,21,0)
CopySprite(count3,22,0)
CopySprite(count4,23,0)

DisplaySprite(20,510,550)
DisplaySprite(21,530,550)
DisplaySprite(22,550,550)
DisplaySprite(23,570,550)
timecount = timecount - 1
Delay(50)
Wend

EndProcedure

The procedure counts down from 1440 and splits
each digit of the number. so I have the sprite number
from my initCounter() and copy it to my created sprites
for each digit (20,21,22,23)

From the main part of the "game" (not yet really one :))
I call

initCounter;
tc_thread = CreateThread(@SetCounter(),0)

The thread is for counting in the background of the later game.

Thats the point. After Compiling the debugger says
at the line
DisplaySprite(23,570,550) in SetCounter()

"#Sprite Object not initialized"

Are The objects global or how do I make them global?


Thanks for your comments, maybe I totally wrong with it
but its my first try on game-programming

Martin Strojek
[url]mailto:martin@solutionworks.de[/url]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

In PB, alls IDs are global. eg Sprite, File, Gadget etc.

I did not tried your example but normaly you could access IDs which are created insite a procedure.

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

hi duschman...
i taked a fast look to your code snip (havent tested it yet) but there is a small point where you will get problems i think! If you want display the counter (time i.e.) all the time to your gamescreen, you have to display *THIS* every frame!!!

In your code snip you are drawing the timer stuff inside your procedure and so the sprites for the counter/timer will only displayed one frame!!! If you come from Amiga Computer you have to think in another way when coding a game for windows... On Amiga for example you have only to draw/redraw the part you want to change on the screen... On Windows you have everytime to draw the complete screen with all elements!!!

If you want always use a thread for your timer (but it isnt really needed when using other ways) you could use a temp value inside your SetCounter() which will increase every 50 millisecs. So you have only to check this temp val inside your mainloop to set your counter to a new val... this could looks like following example (no time for testing it):

Code: Select all

; ------------------------------------------------------------
;
    Global timecount
    ;
    Procedure MySetCounter()
        timecount + 1
        Delay(50)
    EndProcedure
;
; -------- MainLoop --------
;
    tc_thread = CreateThread(@MySetCounter(),0)
    ;
    Repeat
      If timecount = 1
        nextsprite + 1 : timecount = 0 
        If nextsprite = 10 : nextsprite = 0 : EndIf
      EndIf
      ;
      DisplaySprite (20 + nextsprite, 510, 550) 
      DisplaySprite (21 + nextsprite, 530, 550) 
      DisplaySprite (22 + nextsprite, 550, 550) 
      DisplaySprite (23 + nextsprite, 570, 550) 
      ;
    Until ForWhatEverYouWantToWait
    ;
    End
;
; ------------------------------------------------------------
Hope there is no mistake in this hurry and this late time :wink: Maybe you understand the example when using threads i.e.

PS: I havent had the time to test your example... but as i said, your example is not really correct... happy coding... hope this will help you...

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by duschman.

Thanks thorsten for your comment.
I will try it as soon as possible.

The problem might be that I neither come from amiga nor Windows.
I've never programmed any game just tons of web-applications :)

But I'm sure with purebasic and the excellent support I'll become a great game programmer as well :)
Post Reply