Scripting question(s)

JimTheDinosaur

Vault Dweller
Modder
This is probably a very stupid question, but it's something that I just can't seem to figure out and is bothering me immensely.

Basically, the first thing you learn is that every action should have the structure "if... then begin... end" right? But the developers use the simplified "if... then" sometimes as well. So when can you use that and when not?

For instance, I tried the following at map_enter_p_proc somewhere:

Code:
	if( cur_map_index == MAP_BH_RND_DESERT ) then 
      critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_TEAM_NUM,TEAM_PLAYER);
      else 
         critter_add_trait(self_obj,TRAIT_OBJECT,OBJECT_TEAM_NUM,TEAM_DEN_SLAVER);

and it seems to work just fine when I test it.

(By the way, I feel like an obnoxious idiot posting a new thread for each of my questions, but scripting stuff doesn't seem at home in the general mapper thread, so maybe this can be a general scripting questions thread from now on.)
 
JimTheDinosaur said:
(By the way, I feel like an obnoxious idiot posting a new thread for each of my questions, but scripting stuff doesn't seem at home in the general mapper thread, so maybe this can be a general scripting questions thread from now on.)

I think there are dedicated threads to scripting issues, but finding them will require some digging. Maybe the moderators can combine them into one thread and make a sticky. :look:
 
Just compare my examples:

Code:
if X = 1 then begin
   call Node001;
   call Node002;
end
else begin
   call Node003;
   call Node004;
end

And now:

Code:
if X = 1 then
   call Node001;
else
   call Node002;

See the difference? The first block is bigger and includes more lines / line breakups. This is needed, because you cannot write all the commands into one single line.

The second block is very short- you can pretty much write it all in one line:

Code:
if X = 1 then call Node001; else call Node002;

So... long story short, the short version can be used for simple things, where you would never need to break up a line.
 
Keep in mind that you won't be able to add comments behind the lines of the short if-then-else block, as the compiler *will* read it as a single line and spawn an error when it hits the comment. Just saying, because it is easy to make this mistake and then you are searching a while for the location of an error in your script.... :>
 
JimTheDinosaur said:
Basically, the first thing you learn is that every action should have the structure "if... then begin... end" right? But the developers use the simplified "if... then" sometimes as well. So when can you use that and when not?

As a general rule: If-then is used if you want one thing to happen (including if you use an 'else' statement). If-then begin is if you want a number of things to happen. (For example, if you wanted to set two global variables, one local variable, call a float message, and remove an item from inventory all at one time.)
 
One more thing to look out for - some macros from COMMAND.h, DEFINE.h and other header files are used very frequently, but are composed of more than one line of code, so you need to make sure to use them in an if-then begin statement.

E.g.:

Code:
if (source_obj == dude_obj) then begin
   inc_evil_critter
end
 
@Ardent: I didn't know that (since I don't use the header files). But I'll keep this in mind if I ever switch to a more modern compiler/decompiler.
 
Is the obj_dude's code executed while traveling on worldmap? I mean reading, and setting variables. I wrote some sort of global code that must be executed all the time, no matter where the player is (worldmap, any map, or whatever). It's called by timer placed in critter_p_proc (there's no need to check that code every tick/second, or so). Btw, code isn't related to the player in any way, but I needed a script that is present all the time, so obj_dude was the only choice(?).

Thanks in advance.
 
You're using sfall, right? Any global variable there is always on, even on the worldmap. Just make sure have 'gl' at the beginning of the script's name (glcarbrk.int, for example) and that the 'start' procedure is the first one in the script (first mentioned and first called).
 
Continuum said:
Is the obj_dude's code executed while traveling on worldmap? I mean reading, and setting variables. I wrote some sort of global code that must be executed all the time, no matter where the player is (worldmap, any map, or whatever). It's called by timer placed in critter_p_proc (there's no need to check that code every tick/second, or so). Btw, code isn't related to the player in any way, but I needed a script that is present all the time, so obj_dude was the only choice(?).
No, the obj_dude script will not run on the world map. As MIB88 said, an sfall global script is the way to go for that. You do need to do a little bit more than just call it glxxxxx.int though; it needs a

if(game_loaded) then begin
set_global_script_repeat(...);
set_global_script_type(...);
end

block at the beginning for you to set up when and how often it will run. See the first few paragraphs of sfall function notes.txt in the modders pack for more info.
 
This is exactly what do I need. The problem is: I'm scripting things for forgotten shit-engine (aka original Fallout). So... shit :puppy-dog:

-----------------------------EDIT

Meh... workarounds are shit...

I'll put it to freezer labeled: WAITING FOR LESS-SHIT-ENGINE PORT. LESS-SHIT-ENGINE ON STEROIDS DUE TO SFALL INJECTION

:P

-----------------------------EDIT2

nevermind...
 
Timeslip said:
... As MIB88 said, an sfall global script is the way to go for that. You do need to do a little bit more than just call it glxxxxx.int though...

@ Timeslip
I know that. I appreciate your work and use a lot of those scripts. I just didn't want to go into all of it... it would then just obligate me to go into further detail and explain stuff! :P
 
To avoid creating a similar topic i'll make a request here. Can someone be so kind to make a mod that modifies perk rate? With addition of new sfall functions in 3.0.7 it shouldnt be a problem, i guess.

Thanks in advance :)
 
There are commands:
Code:
use_obj_on_obj
Code:
use_obj
but I don't see something like:
Code:
use_skill_on_obj
there's only:
Code:
using_skill
which checks active skill :roll:

How to make few-pixel-puppets using skills on object? I need it for use_skill_on_p_proc in object's script.

Thanks in advance.
 
This is a question I just have probably asked a long time ago, but better late than never: is there a way to divide with the result having decimals?

Let me clarify: when you multiply (i.e. use "*") the result can have decimals (i.e. if you enter 3*0.5, then you get 1.5), however, if you divide the result always has a whole number (i.e. if you use 2/3, the result is 1). The fact that you have both options is really useful because sometimes Fallout accepts decimals, and sometimes it doesn't, but it's really annoying that there's no way to divide with a decimaled result (for instance, I have no idea how you would get a percentage with this system).
 
@Jim
For division, do you know if the answer is being rounded or is the remainder simply being dropped?
 
Glovz said:
@Jim
For division, do you know if the answer is being rounded or is the remainder simply being dropped?

I always assumed it was rounded, but I just tested it and it turns out the remainder is dropped (so I wrongly said that 2/3 returns 1, it actually returns 0).

Edit: I tried adding some decimals myself to the division to see what would happen and the results were... weird. I tried 2.000/3.000 and it returned 0.99611 for some reason.
 
@Jim
My mod uses assembly code and applies the same method that was in the exe for division.

I did some searching for methods of division that do not use the division operator but all seem to only return 0 when the dividend is less than the divisor.

But just to clarify, you are sure other operators will successfully return a decimal?
 
Back
Top