Game Speed Script Code vs Non-Script Code

CodeHunterEx

Hunter of the Perfect Code
Veteran
Joined
Nov 26, 2016
Messages
133
Reaction score
64
First Language
English
Primarily Uses
RMVXA
I was wondering of there is a difference in speed when using more 'script calls' than doing it via normal means.

For me creating script calls to do allot of the work is easier (especially when I can create small codes to do all the creating and all I have to do is copy/paste into the 'script' window), but is having all the script codes any faster?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Script calls use the eval command, meaning that they are compiled and executed once they are triggered. So they are slower than standard code, in fact considerably slower (some experiments show even 600x slower, but there are too many variables to say for certain)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I would say they are faster. Sure it might be slower to execute one line of code via the eval command, but with a script call, you ARE only executing one line of code. With an event command, you could be executing dozens. There's a lot of overhead.

Of course it would require you to use a script call that bypasses all of the intermediate functions (such as using $gamePlayer._direction rather than $gamePlayer.direction())

It would actually be interesting to test this and see the results - maybe something as easy as getting the player's (or an event's) facing direction, or changing their image?
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
If you're only executing it once (not per frame update), don't bother much ...
If you're executing it as a parallel process, maybe might as well as creating a script solely for that, that doesn't require eval command.
 

CodeHunterEx

Hunter of the Perfect Code
Veteran
Joined
Nov 26, 2016
Messages
133
Reaction score
64
First Language
English
Primarily Uses
RMVXA
The insanity behind using the script calls is because I am adding words into my game and I created a small program that took all the words (you DON'T want to know how many) and it created an conditional for each word and then added the words (as variables) in each one.

Example:
if $game_variables[62] == 301
# GENERAL
$game_variables[1] = 7
$game_variables[2] = 5
$game_variables[3] = 14
$game_variables[4] = 5
$game_variables[5] = 18
$game_variables[6] = 1
$game_variables[7] = 12
$game_variables[61] = 7
end

Doing that by hand manually can take a really long time. I use scripts to speed things up a bit.

Edit: I fixed above code. When conditionals are used a double equals (==) is necessary, but when assigning values to a variable a single equals (=) is needed. It slipped by everyone.
 
Last edited:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,354
Reaction score
8,533
First Language
English
Primarily Uses
RMMV

I've moved this thread to Ace Support. Please be sure to post your threads in the correct forum next time. Thank you.

 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
Do whatever is more practical on game making at this point. I can not imagine involving conditional branches for a huge amount of words as you just said. To be honest I fail to see how this could be optimized by using only Conditional Branches. You would just make your life harder and since powerful CPUs become cheaper and cheaper, it won't matter really, because VX Ace games will be playable easier by newer systems while older systems become obsolete even for web browsing.

Sure, you got stuff in Ruby. Ruby is slower eventually, but hey, it is a good trade for what you get.
Performance issues can be raised by other stuff really, like many events set in Parallel at the same map and to make it worse, without a wait command in them.
Scripts CAN cause performance issues, but mostly on using loops and even worse, nesting loops.
Using a ****load of IF statements, nah. I don't believe it would be a problem really, as long as you don't nest them inside a loop.
Oh! Parallel Events are considered a loop too. 60 loops per second.
If you just trigger the script once to check something ad hoc, then you won't have problems though.
 

CodeHunterEx

Hunter of the Perfect Code
Veteran
Joined
Nov 26, 2016
Messages
133
Reaction score
64
First Language
English
Primarily Uses
RMVXA
Do whatever is more practical on game making at this point. I can not imagine involving conditional branches for a huge amount of words as you just said. To be honest I fail to see how this could be optimized by using only Conditional Branches. You would just make your life harder and since powerful CPUs become cheaper and cheaper, it won't matter really, because VX Ace games will be playable easier by newer systems while older systems become obsolete even for web browsing.

Sure, you got stuff in Ruby. Ruby is slower eventually, but hey, it is a good trade for what you get.
Performance issues can be raised by other stuff really, like many events set in Parallel at the same map and to make it worse, without a wait command in them.
Scripts CAN cause performance issues, but mostly on using loops and even worse, nesting loops.
Using a ****load of IF statements, nah. I don't believe it would be a problem really, as long as you don't nest them inside a loop.
Oh! Parallel Events are considered a loop too. 60 loops per second.
If you just trigger the script once to check something ad hoc, then you won't have problems though.

I am sure it would be MUCH better to create a Ruby script that would do all I need, but I am lost trying to do it, so I try and get it done any other way that I can. The best thing would to have an array of words and have it get a word from the array and go from there, but again, I don't know how to do that.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
My take is again, if you do it once, don't bother about it. I mean, the event is only executed once, it doesn't add much impact on performance. Worse, it will be just a slight frameskip, but having frameskip from script call is highly unlikely unless you really have an inefficient script like loading a big bitmap.

The best thing would to have an array of words and have it get a word from the array and go from there, but again, I don't know how to do that.
I'm not sure what you're trying to do. Elaborate?
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
I am sure it would be MUCH better to create a Ruby script that would do all I need, but I am lost trying to do it, so I try and get it done any other way that I can. The best thing would to have an array of words and have it get a word from the array and go from there, but again, I don't know how to do that.
You can have a max of 5000 variables to enter words. But that would be disasterous.

Let me think of it a little...

Okay let's say you gotta get a word out of an array okay?
Let's say that array got only 3 words for our example, and to simplify things, the pointer starts from 1 and not from 0.
So we got for example: Words[1], Words[2], Words[3]

So you need a Common Event to be accessed by everywhere.
You shall reserve
$game_variables[1]
and
$game_variables[2]
for this example, but you can change that, by selecting variables with id of your choice.
For the example though:

$game_variables[1] will work as a pointer of an array.
$game_variables[2] will work as the contents of the array.

You simulate an array that way, but you got data hardcoded instead:


if $game_variables[1] == 1
$game_variables[2] = "Word1"
else
# don't add anything here
end

if $game_variables[1] == 2
$game_variables[2] = "Word2"
else
# don't add anything here
end

if $game_variables[1] == 3
$game_variables[2] = "Word3"
else
# don't add anything here
end

And you are done.
Now you can set up $game_variables[1] using Control Variables.
Then you set the value of $game_variables[2] by calling the script in the common event.

Just a clumsy thought I had. :p


Check this out, it might help you further:
https://forums.rpgmakerweb.com/index.php?threads/script-call-collection-for-vxace.25759/


Edit:
@TheoAllen, me neither, but I made a guess. :p



Edit:

Question is, can we set an array as $game_variables[1]?
We can do that in JS but I am not sure for Ruby.

Second question. Can we set up a global scope array ourselves?
We probably CAN do that, but I am not sure of the commands we shall use, since I don't know Ruby.
 
Last edited:

CodeHunterEx

Hunter of the Perfect Code
Veteran
Joined
Nov 26, 2016
Messages
133
Reaction score
64
First Language
English
Primarily Uses
RMVXA
Lets say you created a program and in the program you created x number of words. All the words would be saved in an array.

You would then have a variable that gets a random number between 0 and x (or 1 and x) depending on if you start with 0 or 1. Once a word is chosen, the program would then do as I did and convert all the letters to values (1 = A, 5 = E, 13 = M, Z = 26). You get it.

I am sure you can do that in Ruby/RGSS, I just don't know how to set that up.I can create some code to do it, but getting it t work as a callable script is confusing.

I tried to create some scripts on my own and they don't end nicely because I just haven't figured out the proper way to create and call them.
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
Easiest way:
Event Commands > Tab 3 > Advanced > Script

So you probably need an array containing the words you need, and some string manipulation magic, happening on a loop for each character in string, and a second array to be filled with the data.
The problem is, that the array would need different amount of variables, thus this becomes a little harder. You will probably need to carry along the length of the word so you can do stuff, or else how will you know how many letters were in that word?
This starts to seem a little more complex than it looked. :p
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
Basically something like this
Code:
module Words
  Letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('')
  List = ["ABSTRACT","WEAPON","ARMOR"] # <-- List all words in array here
end

Words::List.sample.split('').each_with_index do |letter, i|
  puts "Slot #{i} = Will have value #{Words::Letter.index(letter)}"
end
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,038
Members
137,567
Latest member
sashalag
Top