Main Menu

RGB in a Constant?

Started by Silvh, April 09, 2010, 04:46:19 AM

Previous topic - Next topic

Silvh

Well, I've been fiddling around with some stuff (again), and I just can't get the RGB command to Highlight, nor use it.. It simply crashes my application when used like this(No error messages, just saying it stopped working):
Print Str$(RGB(255,255,0))
WaitKey
End


And it gives errors when used like this:
Constant White = RGB(255,255,255)
Constant Black = RGB(0,0,0)
Constant Red = RGB(255,0,0)
Constant Green = RGB(0,255,0)
Constant Blue = RGB(0,0,255)
Constant Yellow = RGB(0,255,255)

"Constants must resolve to a constant value or string"

Any pointers on what I'm doing wrong? Or is there a Library I need to include to get this function to work? I'm currently using the latest version of the Registered PB 1.74 I could find on the forums, should this be of any use.
"All we have to do, is decide what to do. With the code that is given to us"

kevin

#1
PlayBASIC Code: [Select]
  Print Str$(RGB(255,255,0))
Sync
WaitKey



This works fine here.


QuoteAny pointers on what I'm doing wrong?

 dunno, i suspect you're confusing PB with PBFX.  

QuoteI'm currently using the latest version of the Registered PB 1.74 I could find on the forums, should this be of any use.

 
  PB    V1.64k2 (login required)
  PBFX V1.76 (login required)




  Constant White = RGB(255,255,255)
   

  If you run code like this in PB V1.64 (and bellow), the compiler will pre-evaluate then RGB function (executes it at compile time). It can do this because the RGB is internal VM operation.  However, this will not occur in PBFX though, as RGB() is now an bound function.   These can't currently be pre-evaluated at compile time.  So when the compiler attempt to relve RGB(), it executes a dynamic function call.  The result of this is not a constant, but a dynamic v ariable, so it can't be assigned to a constant.  Since the value is not known at compile time.

 

Silvh

#2
Ooooh, How silly of me. I never meant to install the PBFX version I simply followed a few links and got rather confused as to which was which so I just went "What the heck" and downloaded the highest version number I could find.. Thank you for the short explanation and I'll see if using PB 1.64 works. :)

EDIT:
Ran into another issue, I'm not sure if it's just making my Array size too large, or the fact PB can't handle multi-dimensional Arrays, but doing the following results into a Stack Overflow:
Dim SpriteFrames(500,12) ; Holds the data for 500 sprites with each 12 frames.
"All we have to do, is decide what to do. With the code that is given to us"

kevin


Works fine here, i suspect you're not showing the entire program.

Silvh

#4
The entire Database.pba would be..
; PROJECT : Testing..
; EDITED  : 09/04/2010
; ---------------------------------------------------------------------
_SubDatabase:
; ***************
; **** Types ****
; ***************
Type Players
; Core Data
PlrName As String ; The Player's Name
PlrClass As Integer ; The Player's Class
PlrCurHP As Integer ; The Player's Current Hit Points
PlrCurMP As Integer ; The Player's Current Mana Points
PlrMaxHP As Integer ; The Player's Max Hit Points
PlrMaxMP As Integer ; The Player's Max Mana Points

; Position Data
PlrMap As Integer ; The Player's Map ID
PlrPosX As Integer ; The Player's X Position
PlrPosY As Integer ; The Player's Y Position
PlrPhase As Integer ; The Player's Phase

; Visual Data
PlrSprite As Integer ; The Player's Sprite ID
PlrHair As Integer ; The Player's Hair ID
PlrHead As Integer ; The Player's Face ID
PlrChest As Integer ; The Player's Chest Item ID
PlrLegs As Integer ; The Player's Leg Item ID
PlrMainHand As Integer ; The Player's Mainhand Item ID
PlrOffHand As Integer ; The Player's Offhand Item ID
PlrBack As Integer ; The Player's Back Item ID
EndType

Type Server
; Server Data
ServerName As String
ServerIP As String
ServerPort As Integer
EndType

; *******************
; **** Constants ****
; *******************
Constant White = RGB(255,255,255)
Constant Black = RGB(0,0,0)
Constant Red = RGB(255,0,0)
Constant Green = RGB(0,255,0)
Constant Blue = RGB(0,0,255)
Constant Yellow = RGB(0,255,255)

; *****************
; **** Globals ****
; *****************
Global MaxSprites = 5000
Global MyPlayerID = -1

; ****************
; **** Arrays ****
; ****************
Dim SpriteFrames(MaxSprites,12)


Which is called by a Gosub command.

EDIT : Apparently I was supposed to use the Goto command, silly me.
"All we have to do, is decide what to do. With the code that is given to us"

kevin

#5
 if you call this via GOSUB, then at some point, you need to use the RETURN to restore code executions back to the place after the original call.



Here's some tutorials that cover GOTO & GOSUB