Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Compiling scripts at runtime  (Read 2541 times)

0 Members and 1 Guest are viewing this topic.

Mihulik

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 71
    • View Profile
Compiling scripts at runtime
« on: February 19, 2012, 12:36:13 PM »

Hi,
I need to generate scripts dynamically. This is the way I do it:
Quote
Game.ClearScriptCache();
Sleep(5);
var script = new File("volumes.script");
var volumes = new File("volumes.txt");
script.OpenAsText(2);
volumes.OpenAsText(1);
var line = volumes.ReadLine();
while(line != null){
   script.WriteLine(line);
   line = volumes.ReadLine();
}
script.Close();
volumes.Close();

Game.AttachScript("volumes.script");

It works when I run the game from the project manager but it doesn't work in the compiled version (the script is not executed).
Ï need this functionality because I need to let my co-worker change global variables (i.e. the volumes.txt file) at runtime via changing the file.


Is there a way of achieving this?

Thanks a lot for any suggestions! :)
« Last Edit: February 19, 2012, 12:47:40 PM by Mihulik »
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Compiling scripts at runtime
« Reply #1 on: February 19, 2012, 01:08:44 PM »

Based on our irc discussion, here's how it could be done:

Code: WME Script
  1.  
  2. global SfxVolumes = new Array();
  3.  
  4. method InsertVolumeItem(sound,volume)
  5. {
  6.     var item;
  7.     item.sound = sound;
  8.     item.volume = volume;
  9.  
  10.     SfxVolumes.Push(item);
  11. }
  12.  
  13. method ReturnVolumeItem(sound)
  14. {
  15.     for (var a=0; a< SfxVolume.Length;a=a+1)
  16.     {
  17.         var item = SfxVolumes[a];
  18.         if (item.sound == sound) return item;
  19.     }
  20.     return null;
  21.  
  22. }
  23.  
  24.  
  25. method PlaySound(soundFile)
  26. {
  27.     var item = ReturnVolumeItem(soundFile);
  28.     var volume = 100; // default value
  29.     if (item != null) volume = item.volume;
  30.    
  31.     this.PlaySound(soundFile);
  32.     this.SetSoundVolume(volume);
  33. }
  34.  
  35.  
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mihulik

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 71
    • View Profile
Re: Compiling scripts at runtime
« Reply #2 on: February 19, 2012, 04:07:47 PM »

Thanks!
It's a much better solution. ;)
Logged
 

Page created in 0.035 seconds with 20 queries.