ID:179512
 
Ok, here's what I'm trying to do. I'm making news files for my game which I can easily update without having to modify the actual code every time. Currently I am testing it with a file called 'news.txt'. In the Mob Login() proc I have

src<<file2text("news.txt")


I'm not getting any printout from the file though.

What am I doing wrong?

Thanks

Sapphiremagus
sapphiremagus wrote:
src<<file2text("news.txt")


Where is the file located in the directory hierarchy?
In response to Deadron
Deadron wrote:
sapphiremagus wrote:
src<<file2text("news.txt")

Where is the file located in the directory hierarchy?

So in this case, the path should be written in the quotes?

eg:

src << file2text ("c:\byond\bin\news.txt")
In response to sunzoner
sunzoner wrote:
So in this case, the path should be written in the quotes?

eg:

src << file2text ("c:\byond\bin\news.txt")

Not quite like that...the path to the file is relative to the game directory. If news.txt is in the same directory as the game, then "news.txt" will work. If it's in a subdirectory of the game, then "docs/news.txt" would work (where you replace docs with the subdirectory name).

If it's outside the game directory altogether, then probably the absolute path you show would work, but it would probably be better to have the file in the game directory or a subdirectory.
In response to Deadron
It's in the same directory as the game files. I also tried the absolute file path from C:\ (note to others, make sure to write the slashes in a DOS file structure as \\ . . . otherwise you get escape character errors). Neither worked.

<font color=#0000FF>Sapphiremagus</font>
In response to sapphiremagus
sapphiremagus wrote:
It's in the same directory as the game files. I also tried the absolute file path from C:\ (note to others, make sure to write the slashes in a DOS file structure as \\ . . . otherwise you get escape character errors). Neither worked.

What is the content in the file?
In response to Deadron
NEW FEATURES
-----------------------------------------------
Who verb - Find out which GMs are on
Attack Verb - Learn how effective you would be in combat
Weapons - First prototypes are out! Ask a GM for a test run


That's the exact contents of the file.
sapphiremagus wrote:
src<<file2text("news.txt")


Have you tried putting the text in a variable first to see what happens? Like:

var/the_text = file2text("news.txt")
src << the_text


I'm just going through the steps here that I'd try for myself -- I don't know what the problem is...

Also are you SURE that src makes sense in the context you are using it in? Could src be an object other than a mob?
In response to Deadron
I'll give the variable thing a try, it's a good idea. src would have to be a mob since it's referenced by a mob's Login() code

mob
  ...
  ...
  Login()
    ..()
    src<<file2text("news.txt")
  ...



[EDIT]

No change. This is really odd. I even tried switching src with usr with same results. Maybe it'll help with all the code. I didn't post it earlier because I didn't think it was needed (I used the example in the help file, go figure)

Anyway, here goes:

#include
#include

client/base_num_characters_allowed = 3

var
        CP = 25
        SP = 25
        B_STAT_CAP = 5
        STAT_CAP = 12
        ATT_CAP = 6
        B_ATT_CAP = 3
        B_SKILL_CAP = 4
        SKILL_CAP = 6
        news
        wiz_news
        RAIN = 'rain.dmi'
        //SNOW = 'snow.dmi'


        list
                skill_list
                specials
                weather_t
proc
        roll_dice()
                var
                        result

                result = rand(2,12)
                return result;



mob
        var
                MIND = 0
                BODY = 0
                SOUL = 0
                HP = 0
                EP = 0
                SV = 0
                ACV = 0
                DCV = 0
                PCP
                PSP
                P_STAT_CAP = 5
                P_ATT_CAP = 3
                P_SKILL_CAP = 5
                GM = 0
                obj/gettable/weapon
                        weapon

                list
                        skills
                        special
                        attributes
                        defects

        Login()
                ..()
                src<<"
" src<<"
" src<<"

NEWS

"
                src<<"

"
                news = file2text("news.txt")
                src << news
                if(src.GM)
                        src<<"Wizard News"
                        src<<wiz_news
                for(var/mob/M as mob in world)
                        if(M.GM)
                                M<<"[src] has joined the game"

In response to sapphiremagus
sapphiremagus wrote:
I'll give the variable thing a try, it's a good idea. src would have to be a mob since it's referenced by a mob's Login() code

Are you sure that mob.Login() is ever getting called? Does the other stuff in that proc happen? If you have mob subclasses that override Login(), they might not be calling the superclass (which you do with ..()).

If you'd like you can zip up the project and email it to me, and I'll try to see what's happening tonight or tomorrow.
In response to Deadron
*growls and snarls at Win 98* I figured it out. I was saving text files from note pad including the .txt extension . . . . . . evidently Win 98 ALREADY adds an extension and will not show it to you in your directory. Oi vey. I fixed it and it works fine now. Sorry for all the trouble =P Blame Bill Gates ;-) And thanks for the help Deadron, I appreciate it.

<font color = #0000FF>Sapphiremagus</font>
In response to sapphiremagus
sapphiremagus wrote:
*growls and snarls at Win 98* I figured it out. I was saving text files from note pad including the .txt extension . . . . . . evidently Win 98 ALREADY adds an extension and will not show it to you in your directory. Oi vey. I fixed it and it works fine now. Sorry for all the trouble =P Blame Bill Gates ;-) And thanks for the help Deadron, I appreciate it.

No problem.

And this is why Mac OS X removes the file extension it was using if you add one of your own...
Not being bothered with replying to any of the posts deeper in the thread, I'll just tell you the answer...

You need to tell BYOND that "whatever.txt" is actually a file... the way you have it set up:

usr << file2text("whatever.txt")

you are just giving it a text string ("whatever.txt").

You need to actually make it a file:

usr << file2text(file("whatever.txt"))
In response to Spuzzum
Spuzzum wrote:
Not being bothered with replying to any of the posts deeper in the thread, I'll just tell you the answer...

Bzzt! Wrong, shoulda read the rest of the thread!
In response to Deadron
Bzzt! Wrong, shoulda read the rest of the thread!

Well, I couldn't be bothered to. Nothing will change that decision, because it has already been made, and the damage has been done. ;-)