Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Cannot perform 'string' cast on type '&Play_A_Round' at line 36.

Author
Message
lovecraft58
9
Years of Service
User Offline
Joined: 30th Nov 2014
Location: United States
Posted: 19th Dec 2014 12:48 Edited at: 19th Dec 2014 12:58
I'm using the book DarkBASIC Programming for the Absolute Beginner by Jerry Lee Ford, Jr. and I've typed in t he Tic tac Toe game and I keep getting this error on compile.

"Cannot perform 'string' cast on type '&Play_A_Round' at line 36."


I'm posting a snippet of code. If you want more code, just ask. I'm stumped.

[CODE]
`Define the game`s global variable and assigb ibitial values
GLOBAL Player$ AS STRING = "X" `represebnts current player
GLOBAL Winnert$ AS STRING = " " `used to store game results
GLOBAL NoMove AS INTEGER = 0 `keeps count of number of moves made
GLOBAL Message$ AS STRING = " " `used for diplay of indtructions
GLOBAL Choice$ AS STRING = " " `contrls main loop

`variables of the squares on the board
GLOBAL a1$,a2$,a3$,b1$,b2$,b3$,c1$,c2$,c3$ AS STRING

Welcome_Screen()


SET TEXT FONT "Courier" `Set the font type to Courier
SET TEXT SIZE 24 `Set the font size to 24 points
SET TEXT TO BOLD `Set text to display in bold print
ForegroundColor = RGB( 0, 0, 160) `Set foreground color to blue
BackgroundColor = RGB( 255, 255, 255) `Set background color to white
INK ForegroundColor, BackgroundColor `Apply color settings


DO `Loop forever

`Call the function that prompts player for permission to start the game
Choice$ = Play_A_Round()
IF Choice$ = "PLAY" `The player has elected to play a round
Reset_Board() `Call the function that prepares the game board
Play() `Call the function that controls game play
ELSE `The player wants to end the game
Closing_Screen() `Call the function that displays the closing screen
EXIT `Terminate the loop`s execution
ENDIF

LOOP

END `Terminate the execution of this application[/CODE[\
[/CODE]

And here's the function

[CODE]
`This function prompts the player for permission to play a new game
FUNCTION Play_A_Round()

DO `Loop forever

CLS RGB( 255, 255, 255) `Set background color to white
PRINT : PRINT : PRINT : PRINT : PRINT `Print five blank lines
`Prompt the player for permission to start a new round of play

INPUT " Type PLAY to start a new game or QUIT to end game. ",
Reply$,
Reply$ = Upper$( Reply$) `Convert the player`s input to uppercase

`Determine if valid input was provided
IF Reply$ = "PLAY" or Reply$ = "QUIT"
EXIT `Exit the function
ENDIF

LOOP

ENDFUNCTION Reply$

[/CODE]

Nick Z.

29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 20th Dec 2014 01:39
Hi, I've had a look at this and couldn't figure out what was wrong. I got a couple of syntax errors, which I fixed, but didn't see the error you're getting.

Might be best if you post the whole thing, upload it if you feel it's too big for a code box (you might want to sort out your code tags). DBPro has been known to give the incorrect line number to where the error actually occurred.

WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 20th Dec 2014 02:13 Edited at: 20th Dec 2014 03:22
This is not the problem, but I thought I would point it out anyway. When using the string suffix ($) you do not need “as string”. If you use “as string” you do not need the string suffix. In the loop inside the function you should use “exitfunction” to exit the loop. Give this a try.

lovecraft58
9
Years of Service
User Offline
Joined: 30th Nov 2014
Location: United States
Posted: 22nd Dec 2014 09:16
Thanks all. I seem to have fixed it only I don't know how.

Nick Z.

Login to post a reply

Server time is: 2024-11-27 05:30:30
Your offset time is: 2024-11-27 05:30:30