Jump to content




Load a files code and run it in a different program


9 replies to this topic

#1 Varscott11

  • Members
  • 23 posts

Posted 28 August 2016 - 01:02 AM

This has stumped me for a long time now. I have two files:

file1:"unet"
file2:"unetclientdata/libraries/rnetconfigx12"

I need the unet program to load the entire file, rnetconfigx12, and run it as if the code for file2 was part of file1.

Sorry if this is too much, but I also need them to be compatible with each other. As in file 2 can call functions from file 1 and vise versa.

Any help is appreciated!

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 August 2016 - 01:37 AM

This PIL Chapter may be of use to you.

#3 Varscott11

  • Members
  • 23 posts

Posted 28 August 2016 - 01:56 AM

I took a look at the PIL, and had some trouble with it. But what I have gathered is that I might need to use loadfile to get the code over to file1? correct me if i'm wrong

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 August 2016 - 02:05 AM

loadfile would be one of the ways, yes.

#5 Varscott11

  • Members
  • 23 posts

Posted 28 August 2016 - 02:09 AM

If I do loadfile, will that allow for one file to call functions of the other?

#6 Varscott11

  • Members
  • 23 posts

Posted 28 August 2016 - 03:49 PM

I have tried loadfile, and the other script runs like it should. Sort of. The two scripts however don't communicate with each other, and I cannot call functions that are stored in the other file correctly. Any ideas?

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 August 2016 - 04:45 AM

View PostVarscott11, on 28 August 2016 - 01:02 AM, said:

As in file 2 can call functions from file 1 and vise versa.

This sounds ominous - there's seldom good reason to go both ways like that. Are you planning on making recursive calls? If so (and if you don't understand what they are, assume "yes"), are you aware of the potential pitfalls?

If you really "must" store your code across multiple files, then your main problem boils down to scope. You can share the global environment between your separately loaded files, but I'm not aware of any way to do this with values declared local to the individual files.

I'm strongly suspecting that you'd be better off looking into CC's API system.

#8 Varscott11

  • Members
  • 23 posts

Posted 29 August 2016 - 03:24 PM

I have taken into account the api system and have even employed it once in the code. However I still was not able to call functions properly and it came up with an error that said the function I was asking for was a nil. I've looked over both scripts and they are both pretty close to devoid of bugs, as I debug as I go. I really don't know what I'm doing wrong. It might be a bug in my code, which I could sort out, but I need to make sure that what I do, can atleast call functions from the other script.

P.S Thanks for the help so far. :)

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 30 August 2016 - 05:47 AM

Odds are someone could point out the problems to you if you were to display your code.

http://www.pastebin.com

#10 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 30 August 2016 - 08:06 AM

You may want to have a look at Howl: http://www.computerc...a-build-system/





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users