Author Topic: Function ByRef  (Read 1176 times)

0 Members and 1 Guest are viewing this topic.

Offline kepp

  • Scripter
  • King
  • ******
  • Posts: 790
  • Karma: +2/-0
Function ByRef
« on: 15 November, 2004, 22:58:46 »
I have a little problem

I would like to load a textfile into Settings.Main.General.Hubad       table

and this code works just great to do so

Code: [Select]
function LoadTextFile(file)
   local sMessage = "";
   readfrom(file)
   while 1 do
      local line = read();
      if line == nil then break
      else
      sMessage = sMessage..line.."\r\n";
      end
   end
   Settings.Main.General.Hubad = sMessage;
end

but i would like this to work for other things aswell
so i edited it a little :

Code: [Select]
function LoadTextFile(obj,file)
   local sMessage = "";
   readfrom(file)
   while 1 do
      local line = read();
      if line == nil then break
      else
      sMessage = sMessage..line.."\r\n";
      end
   end
   obj = sMessage;
end

when i call this function it looks like : LoadTextFile(Settings.Main.General.Hubad,"File")

BUT, dosen't work, Anybody knows why or what im doing wrong??
Guarding    

PtokaX forum

Function ByRef
« on: 15 November, 2004, 22:58:46 »

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #1 on: 16 November, 2004, 01:45:24 »
try like this.
Code: [Select]
function LoadTextFile(file)
   local sMessage = ""
   readfrom(file)
   while 1 do
      local line = read()
      if line == nil then break
      else
  sMessage = sMessage..line.."\r\n"
      end
   end
   readfrom()
   return sMessage
end

Settings.Main.General.Hubad = LoadTextFile("File")

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

PtokaX forum

(No subject)
« Reply #1 on: 16 November, 2004, 01:45:24 »