Execute Code vs Execute Script

G

gamedev513

Guest
Hey everyone,

Kind of a noob question, however, here it goes. What are the major differences between running code via Execute Code action vs. Execute Script action. What is the difference between running an Execute Code action with the following code in it:

Code:
scr_myscript();
versus just selecting the Execute Script action for an object and selecting scr_myscript and leave arguments as 0?

Thanks!
 

NazGhuL

NazTaiL
with Execute Code you can add thing that are not script:

Code:
scr_myscript();

x = 123;

//comments...

a = b+2;
 
F

Fuzenrad

Guest
With script you have arguments that can be previously set when you call, the 'Execute Code' is when you need a local code in a object, something simpler (not necessarily), both run at the same speed.
 

TheouAegis

Member
Using execute_code associates the code with the object, so when the object data is loaded into the PRAM, the code likely is too. When you use execute_script, the script is not necessarily loaded into the RAM at the same time as the object, so its code may not be readily available. Furthermore, when using execute_code, the code is performed instantly. When using script_execute, each of the arguments must first be loaded into the register(s) and saved to the RAM, even if they're all left blank, then the memory address of the script needs to be loaded into the register and the current address pushed to the stack. If the script hasn't be loaded into PRAM yet, it gets loaded, then the code in the script is executed. After the script has been executed, the previous address is retrieved from the stack and you go back to the object code.

It's understandable why people would think they're practically equally fast, but all-in-all, execute_script is actually twice as slow as execute_code.
 

Yal

🐧 *penguin noises*
GMC Elder
execute_script() lets you avoid repeating yourself, executing code lets you cut down on managing your script collection. I only ever use the execute-code action in my games nowadays, but a lot of those contains script calls. Long story short, why choose between cinnamon and butterscotch when you can have both? Both are useful, they're just useful in different situations.
 
A

Annoyed Grunt

Guest
I never use Execute Script, ever. Even if I need to execute a single script, I'll add a execute code and call the function.
It makes it much easier to edit if I need to add more things.
 

Yal

🐧 *penguin noises*
GMC Elder
I never use Execute Script, ever. Even if I need to execute a single script, I'll add a execute code and call the function.
It makes it much easier to edit if I need to add more things.
execute_script() (the function, that is - I'm with you about always using code actions) is pretty handy, though, since you can use it to execute variable scripts, e.g. for script-based-state state machines. (Infinite State Machines? :p)
 

hippyman

Member
I use execute script as a way to "sort of" have methods with objects.

I made a special script called script_execute_array which is the same thing as script_execute but rather than putting your arguments in one at a time you put all your arguments in an array and then put the array as a whole in for the argument.

Then the script figures out how many arguments there are and calls it accordingly. It's not perfect, but it's occasionally handy.

Edit: I should mention that this is the ONLY time I use it though. I can't remember who tested it, but I vaguely remember somebody saying they did some tests and determined that execute_script is actually a good bit slower than execute_code. 100% hear-say right now and I don't plan on testing it so take that with a grain of salt.
 

NicoDT

Member
I'll show you the way I use script_execute(), it may help you

Let's say that I have a grid with skills that looks something like this

global.skills(0,0) = "thunder"
global.skills(1,0) = scr_thunder
global.skills(0,1) = "fire"
global.skills(1,1) = scr_fire
global.skills(0,2) = "ice"
global.skills(1,2) = scr_ice

With the following code, I could execute the skill's script easily

Code:
if (key_accept)
{
  script_execute(ds_grid_get(global.skills,1, pos))   // pos = position of the cursor in the skills menu
}
 
Top