Femics Questions & Answers Q&A

Femic

First time out of the vault
Hi all,

why should I use the keyword export variable and import variable?
Are they any advantages opposite to LVAR MVAR and GVAR?

Let's assume I do this:
Code:
ScriptA.ssl

export variable C
C := 99;
Code:
ScriptB.ssl

import variable C

Will variable C contain value 99 after importing it?

Thanks and regards.
 
That variable is temporary and will be forgotten on map change / game load. LVARs etc. are saved and remembered.
 
What is the difference between these three macros?
In Sfall Script Editor following happens.
When I hover over the yellow macro I get a description that looks like a basic command description but it doesn't tell me where this macro has been defined.
The description of the purple and white macro shows the whole content that has been replaced by the macros and it tells me where is has been defined.





 
Last edited:
That variable is temporary and will be forgotten on map change / game load.
The import/export variable value will be saved while the script is running, i.e. before unloading the script in which the export is defined (usually the export is done to the map script). If the export is declared in a global script, it will be permanent.
 
What is the difference between these three macros?
The dark-orange ones are not macros, they are vanilla opcodes of the engine.
The yellow ones are standard macros. A standard description is defined for them. (can go to the macro via the context menu)
Macros of purple and other colors do not have a specific description. The white ones are usually user macros.
 
Last edited:
I never got how export/import work.
Do they get exported into global namespace? What if multiple scripts import the same var? Will they work with the same instance of it or private copies?
Also, it says "export variable" Is it possible to export, say, procedures or something else?
 
>Do they get exported into global namespace?
---
yes.

>What if multiple scripts import the same var?
---
everyone will get the exported value.

>Also, it says "export variable" Is it possible to export, say, procedures or something else?
---
You can export procedures.
 
What is meant by "global namespace"?
Does it mean that if you declare "export variable" into a global script or a header file like global.h, the name of the exported variable can only be used once anywhere?
 
What does this do? I don't get what obj_art_fid is good for, what FID_HMWARR and FID_HFPRIM mean.

Code:
procedure talk_p_proc begin

   if ((obj_art_fid(dude_obj) == FID_HMWARR) or (obj_art_fid(dude_obj) == FID_HFPRIM)) then begin
 
FID is the defined art ID of the current critter (artfid.h). In this case it checks if the player is male or female tribal.
 
I want to script an event where the player uses the science skill on a nuka cola vending machine. After the fiddling animation the player should perform a kick animation and receive 20 bucks and a nuka cola.

My script looks like this:

Code:
#include "..\headers\define.h"
#include "..\headers\command.h"

procedure start;
procedure description_p_proc;
procedure look_at_p_proc;
procedure use_skill_on_p_proc;

procedure start begin
end

procedure look_at_p_proc begin
   script_overrides;
end

procedure description_p_proc begin
   script_overrides;
end

procedure use_skill_on_p_proc begin
   if (action_being_used == SKILL_REPAIR) then begin
           anim(dude_obj,ANIM_kick_leg,ANIMATE_FORWARD);
      item_caps_adjust(dude_obj, 20);
      add_obj_to_inven(dude_obj, PID_NUKA_COLA);
      end
end

I open the BIS mapper and attach this script to a vending machine. F8 to test the script and when I command the player to use science on the vending machine he fiddles and the mapper crashes.

What is wrong with my code?
 
Try this

Code:
variable training_anim := ANIM_kick_leg;
variable sound := sfx_build_char_name(source_obj, training_anim, snd_contact);

   reg_anim_clear(source_obj);
   reg_anim_begin();
   reg_anim_animate(source_obj, training_anim, -1);
   reg_anim_play_sfx(source_obj, Sound, 0);
   reg_anim_end();
 
Thx @Lexx

I wrote it like this:
Code:
procedure use_skill_on_p_proc begin

variable training_anim := ANIM_kick_leg;
variable sound := sfx_build_char_name(source_obj, training_anim, snd_contact);

   if (action_being_used == SKILL_REPAIR) then begin
         reg_anim_clear(source_obj);
         reg_anim_begin();
         reg_anim_animate(source_obj, training_anim, -1);
         reg_anim_play_sfx(source_obj, sound, 0);
         reg_anim_end();
      item_caps_adjust(dude_obj, 20);
      add_obj_to_inven(dude_obj, PID_NUKA_COLA);
      end
end
The mapper crashes anyways :/




I found the culprit who crashes the mapper. It's:
Code:
item_caps_adjust(dude_obj, 20);
add_obj_to_inven(dude_obj, PID_NUKA_COLA);




This code works:
Code:
procedure use_skill_on_p_proc begin

variable training_anim := ANIM_kick_leg;
variable sound := sfx_build_char_name(source_obj, training_anim, snd_contact);

   if (action_being_used == SKILL_REPAIR) then begin
         reg_anim_clear(source_obj);
         reg_anim_begin();
         reg_anim_animate(source_obj, training_anim, -1);
         reg_anim_play_sfx(source_obj, sound, 0);
         reg_anim_end();
//      item_caps_adjust(dude_obj, 20);
//      add_obj_to_inven(dude_obj, PID_NUKA_COLA);
      end
end
But no more cash and nuka cola :/
I'll find a solution.



This son of a bitch is causing the mapper crash:
Code:
add_obj_to_inven(dude_obj, PID_NUKA_COLA);




Okay. I found the solution:
Code:
procedure use_skill_on_p_proc begin

variable item;
variable training_anim := ANIM_kick_leg;
variable sound := sfx_build_char_name(source_obj, training_anim, snd_contact);

   if (action_being_used == SKILL_REPAIR) then begin
         reg_anim_clear(source_obj);
         reg_anim_begin();
         reg_anim_animate(source_obj, training_anim, -1);
         reg_anim_play_sfx(source_obj, sound, 5);              // changed 0 to 5.
         reg_anim_end();
      item_caps_adjust(dude_obj, 20);
      item:=create_object(PID_NUKA_COLA,0,0);
      add_obj_to_inven(dude_obj,item);
   end
end
Btw. I changed the delay from 0 to 5, so it fits better with the animation :)
 
Last edited:
Now that the script works and the player receives 20 caps and a Nuka-Cola, I want to alter the object selection.
I already changed this line:
Code:
item_caps_adjust(dude_obj, 20);
to this:
Code:
item_caps_adjust(dude_obj, random(1,20));
Now the player receives a random amount of caps between 0 and 21.
Is it possible to define three pid objects and randomly add one of them to the players inventory instead of only the Nuka-Cola?
I tried it with arrays but I couldn't make it work.
 
Try this:

Code:
item_pid = random(1,1); // 1,2? 0,2?
 if (item_pid==0) then item_pid=PID_NUKA_COLA 
 if (item_pid==1) then item_pid=PID_ITEM2
 if (item_pid==2) then item_pid=PID_ITEM3

item:=create_object(item_pid,0,0);
 
Omfg! It worked! Thx @Zorchar.

The code looks like this:
Code:
variable item_pid;
variable item;

     item_pid = random(0,2); // 1,2? 0,2?
   if (item_pid == 0) then
      item_pid = PID_NUKA_COLA;
   else if  (item_pid == 1) then
      item_pid = PID_COOKIE;
   else if (item_pid == 2) then
      item_pid = PID_BEER;
      item := create_object(item_pid,0,0);
      add_obj_to_inven(dude_obj,item);
 
Array:
Code:
#include "sfall/lib.arrays.h"

...

variable Items_List, Item;

   Items_List := [PID_NUKA_COLA, PID_COOKIE, PID_BEER];
   Item := array_random_value(Items_List);
   Item := create_object(Item, 0, 0);
   add_mult_objs_to_inven(dude_obj, Item, 1);
 
Is there a way to to put two files, e.g ssl and msg file, beside to each other inside the sFall script editor?
 
Don't think so... You could open the msg file in a different editor like NotePad++ to place them besides each other though.

I simultaneously use two VMs so that I can have different tools open on each. Makes it a bit easier to open the mapper next to the script, or have both the msg and ssl file open for example. (What a luxury we live in these days :))
 
Back
Top