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.

DarkBASIC Professional Discussion / Write File - signed int?

Author
Message
Gunslinger
19
Years of Service
User Offline
Joined: 29th May 2007
Location:
Posted: 24th Feb 2012 00:48 Edited at: 24th Feb 2012 00:58
Hello,
how can i save / read a negativ integer to a file?
Is there a undocumented signed command?

Like
unsigned byte -> 0->255 (normal)
signed byte -> -128 -> +127

write log:
Tile: 6/4
Type#: 2
TextureID#: 2
x#: 6
y#: -1
z#: 4

read log:
Tile: 6/4
Type#: 2
TextureID#: 2
x#: 6
y#: 65535
z#: 4



Edit: Okay, used the search. It's allways unsigned, but found a workaround.


Should do it.
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 24th Feb 2012 13:19 Edited at: 24th Feb 2012 13:20
to write u whave to use "write string" instead. using the str$() command to convert the integer/float or whatever to an string and write it to file


to read it, you do next:
open to read 1,"myfile.txt"
repeat
read string 1,ss$

sf$ = "x: "
if left$(ss$,len(sf$)) = sf$ then x# = val(right$(ss$,len(ss$)-len(sf$)))

sf$ = "y: "
if left$(ss$,len(sf$)) = sf$ then y# = val(right$(ss$,len(ss$)-len(sf$)))

sf$ = "z: "
if left$(ss$,len(sf$)) = sf$ then z# = val(right$(ss$,len(ss$)-len(sf$)))


until file end(1)
close file 1

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Feb 2012 14:33
No, Gunslinger has it right. There's no need to switch to a text-based format unless you want it to be human-readable or human-editable.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Feb 2012 15:47
Quote: "how can i save / read a negativ integer to a file?"


Like this. No workarounds necessary. Integers are four bytes in length, the same as dwords and floats.



The thing to remember is that integers are output as dwords but DBPro automatically converts back to integers if you try to read a dword ("long") into an integer variable.

Login to post a reply

Server time is: 2026-07-10 00:43:05
Your offset time is: 2026-07-10 00:43:05