forums

TNT Basic Forums > Programming Q&A
Integers and pixel co-ordinates
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-23-2002 18:41

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Hi,

How can I get a integer to store a pixel reference? At the moment TNT comes up with 'Expected a variable". The idea being, is that the user can type in a reference code, and a sprite is moved there.
e.g.
int A1=50,50
int A2=70,70
. . . .
'Few more of these...

if Inchar="A" and "1" or "2" then
sprite mouse x, mouse y int A1 or A2
. . . .
'Few more of these again...
end if

Also, the 'Int' before A1 would be highlighted as 'Expected an open bracket' and the end number on the above line not being recognised as a numeric value. Am I going about this the wrong way or is it just buggy?

thanks in advance for anyone who can help,
Mark_667

12-23-2002 18:54

Posted by:
jamie

Click Here to Email jamie   Find more posts by jamie

variables

I believe you would need to do it something like this:

int A1=50, A2=50
int B1=70,B2=70

you can't set up one variable to hold two values

then when you want to place the sprite do something like:

Sprite spriteID,A1,A2,image

hope this helps....

01-27-2003 08:45

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Selecting sprites from file

Hi,
Re the same topic, for my code I need the program to choose the sprite from a file, which the user's previous choice was written to, and then move it to the co-ordinates given by the integers A1 and A12. I have tried a few ways, and as you can see in the example below, the only way I can think of is as below. However, TNT comes up with an error for 'file', if I swap the positions of 'read' and 'file' the same will still happen.

int file
file=open file ("Mini Chess:kFileName", true, kFileType)

if pressed(0) and (18) 'A and 1 Move sprite at mouse click to these co-ordinates...
sprite=read file,A1, A12 'Need code here to find out how to select a sprite from a string value in a file
else if pressed (0) and (19)
sprite=read file,A2,A22

'few more of these...

end if

Any help appreciated,
Mark_667

01-27-2003 17:37

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Check your reading syntax...the commands are:
file read int(fileID) '"fileID" is the value returned by the
'"open file" or "ask open file" command
file read string(fileID)
file read float(fileID)


||sprite=read file,A1, A12 'Need code here to find out how || to select a sprite from a string value

About the above exerpt, are you assigning a value to the variable sprite or trying to create a sprite, in which case you would write:

int SpriteID
spriteID=file read int(fileID)
sprite spriteID,A1,A12,imageNum 'ImageNum is the ID of the
'picture you use for this sprite

same with this code
||else if pressed (0) and (19)
||sprite=read file,1,A22
||
||'few more of these...

you need to fix the syntax of your commands. Use the TNT Basic help if you have it.

And sorry if I explained the obvious, I wasn't sure if you knew any of this already :)

01-29-2003 22:46

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

If statements

There's a couple of bugs in your code which will cause you problems later on:

if pressed(0) and (18)
....
else if pressed (0) and (19)
.....
end if

if Inchar="A" and "1" or "2"
. . . .
end if

If you use an and or an or in an expression, you must provide a complete expression in either side of the and/or, the two halves are completely independent. In these examples you mention a variable and a value on one side of the and/or, and then only a value, but not a variable on the other. You code should read:

if pressed(0) and pressed(18)
.....
else if pressed(0) and pressed(19)
.....
end if

if InChar="A" and somethingelse="1" or somethingelse="2"
......
end if

If you write simply:

if myVariable=1 or 2
........
end if

Then the expression is true if '2' or separately if 'myVariable=1'. The two sides of the or/and are evaluated completely independently.

Non zero numbers are 'true' all the time. So '2' would always be true which would mean that the above if statement would always be true and the code inside the if statement would always be executed, regardless of the value of myVariable.

Hope this helps,

Mark

01-29-2003 23:46

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

Hope this clarifies a few things... :-)

01-30-2003 12:33

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Re: the above advice

Hi,
thanks for the sugesstions, just a few things, as you can see below, I've made the changes suggested, but because I don't know what the sprite is (which is variable anyway because the user can pick different ones, which are then logged for reference) until TNT reads the file, I can't assign an image num. TNT doesn't report an error when it is ignored, but is does highlight the line: spriteID= file read int (fieldID) as an illegal procedure call. I checked the syntax in the User Guide, and it looks OK to me any ideas anyone?

int fieldID
fieldID=open file ("My Game:kLogFileName", true, kLogFileType)

int SpriteID
spriteID=file read int(fieldID)

if pressed(0) and pressed (18) 'A and 1
spriteID= file read int (fieldID)
file read int (fieldID)
sprite spriteID,A1, A12, image num 'Move sprite at mouse click to these co-ordinates..
else if pressed(0) and pressed (19) 'A & 2
spriteID= file read int (fileID)
sprite spriteID,A2, A22, image num

'blah, blah

end if

Thanks in advance on this matter, probably just something simple but . .

Mark_667

01-31-2003 02:23

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

A few things:

spriteID= file read int (fieldID)
file read int (fieldID)

the first line is correct; it stores the value of "file read int(fieldID)" into a variable. The second line must be in the form "variable = file read int (fieldID)" I'm not sure if you want that line there at all anyway.

Second, in these two lines,

||sprite spriteID,A1, A12, image num 'Move sprite at mouse

and

||sprite spriteID,A2, A22, image num

if image num is a single variable it can't have a space between.

Third, did you mean "fileID" and "fieldID" to be different variables, or are they typos? :)

Hope this helps

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.