Author Topic: File Creation Issue  (Read 7876 times)

0 Members and 1 Guest are viewing this topic.

Offline spathi

  • C= 64
  • **
  • Posts: 78
  • Karma: 5
    • View Profile
File Creation Issue
« on: December 13, 2011 »
I'm running into a bug that I ran into before on Blitz.

It will not open a file for write if I do so based on user input using this code:

Code: [Select]
while(1)
tempchar=GetChar()
If tempchar>0 inputtext=inputtext+Chr(tempchar)
savedialog.typedtext=inputtext


If KeyDown(KEY_ENTER)

FlushKeys()
DOES NOT WORK: Local out:TStream=WriteStream(savedialog.typedtext) (this is just a string!)
WORKS:                   Local out:TStream=WriteStream("bluedemon")
CloseStream (out)

EndIf
wend

Is there something going on with newlines or something that I'm not aware of?  Is using KEY_ENTER to exit the loop stripping a newline off of the end of the file that should be there?

It doesn't error or anything, it just doesn't create any file.  The other file creation method using CreateFile does not work either which leads me to believe that it must be some sort of bug in my user input code that I am not aware of...

Since I know some people like screenshots, here is the titular blue demon:


This is for a voxel dungeonshooter/roguelike I am working on called Dungeonslayers.  The whole gui toolkit is written by me-- it doesn't look like much but it has control arrays, sliders, and radio buttons.
« Last Edit: December 13, 2011 by spathi »

Offline spathi

  • C= 64
  • **
  • Posts: 78
  • Karma: 5
    • View Profile
Re: File Creation Issue
« Reply #1 on: December 17, 2011 »
The issue is something with my user input routine-- I don't see why my input would produce a string that is indistinguishable from a hard-coded filename, and why it will work if I cut it and paste it into a hardcoded call eg. writegrid ("pastedtexthere")  This makes me think it's something to do with string termination.

But whatever, I just used input a$.  It's ghetto but it's just an editor for me so it doesn't matter that it shows up on the console and not in the GUI.

I first typed the character string "input a$," or rather "INPUT A$," almost exactly 32 years ago today.
« Last Edit: December 17, 2011 by spathi »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17427
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: File Creation Issue
« Reply #2 on: December 19, 2011 »
I first typed the character string "input a$," or rather "INPUT A$," almost exactly 32 years ago today.

I think it was about the same for me! 
I'm sorry that I don't know the answer to the file problem though.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: File Creation Issue
« Reply #3 on: December 19, 2011 »
It looks from your code that when you type it in to the input box you are getting the 'Enter' key at the end of the string (an extra asc(13)), whereas when you type it direct in the code the string is OK.
Try this:
Code: [Select]
savedialog.typedtext = Left(savedialog.typedtext,Len(savedialog.typedtext)-1)
which will trim off the last character.

Jim
Challenge Trophies Won:

Offline spathi

  • C= 64
  • **
  • Posts: 78
  • Karma: 5
    • View Profile
Re: File Creation Issue
« Reply #4 on: December 20, 2011 »
That must be it.  I should have tried truncating it, I had a vague idea of what the problem was.  Thanks!  Now I find that the Blitz gui is free... maybe I will experiment with that instead of continuing to try to roll my own, but I have certainly learned a lot about it.

This is a sort of illustration of the double edged cognitive sword of caffeine.  Caffeine giveth but caffeine also taketh away.
« Last Edit: December 20, 2011 by spathi »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17427
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: File Creation Issue
« Reply #5 on: December 20, 2011 »
This is a sort of illustration of the double edged cognitive sword of caffeine.  Caffeine giveth but caffeine also taketh away.

That's why beer makes it possible!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline spathi

  • C= 64
  • **
  • Posts: 78
  • Karma: 5
    • View Profile
Re: File Creation Issue
« Reply #6 on: December 20, 2011 »
Does beer help?  I don't go near alcohol.  Maybe I should start.  Caffeine has sort of a magic zone that you can get into but it's sort of a narrow one and sometimes it just doesn't work and ends up making you feel all weirded out and jittery, and unable to debug code until the sensation wears off.

Cannabis gives me all sorts of amazing ideas but takes away all my motivation to program.

LSD?  Never tried coding on that but I bet it would be interesting... maybe I will start putting out some feelers.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17427
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: File Creation Issue
« Reply #7 on: December 20, 2011 »
True story here Spathi, I remember being ill in work because of coffee!

I'd had 2 large americanos from the coffee shop and about 15 cups of coffee from the machine and I had chest pains and difficulty breathing.. I had to go outside and have a walk around - I thought I was dying though!

Scary shit.

LSD is possibly*  safer


* Disclaimer - winners don't do drugs!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline spathi

  • C= 64
  • **
  • Posts: 78
  • Karma: 5
    • View Profile
Re: File Creation Issue
« Reply #8 on: December 20, 2011 »
Well if you have fifteen cups of coffee that will do it for sure. 

Coffee can actually kill you.  There are many cases of Russians in particular who have died from it because of their use of samovars which brew a thick black tar.

I think LSD probably causes some sort of receptor burn effect if you take too much of it or possibly for too sustained a period, there are many anecdotes about people who were never the same.  On the other hand that may not be true and we will never know... still I want to try a coding run on it [if I did that sort of thing which I never, ever, EVER would.]


Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: File Creation Issue
« Reply #9 on: December 20, 2011 »
Sorry about the late answer, but good to see someone already gave you some usable feedback. But yes when using the getchar command, the enter key gets recorded as well unless you code deals with it. The blitzmax gui module is fairly easy to get your head around and as you mention it is now free for everyone with a blitzmax license to use without restrictions.