02-09-2021, 10:45 AM
(This post was last modified: 02-09-2021, 10:55 AM by MetalRenard.)
Part 2!
Goal: Be able to change the character's rotation speed (they look at the mouse).
So the above script runs in the background and is used to store data. Now I want to access this data from another script called 'Player'.
It took me a little while to work this out because it requires specific formatting to tell the engine where to look.
Here's the updated GlobalPlayer script.
I'm checking to see what the rotation speed of the player is in position 0 of the dictionary's "rotation" array.
The thing that took me ages was learning how to look at data stored in an array which is stored in a dictionary! Finally arrived to this conclusion, very happy.
Next step: Use the _lvl variables to store the player's level and use that to compare with the position in the dictionary.
To accomplish this, I added these varibles above the Player script and compared them to the GlobalPlayer variables.
And then updated the formula to compare the player's level to the position in the array.
It works!
Goal: Be able to change the character's rotation speed (they look at the mouse).
So the above script runs in the background and is used to store data. Now I want to access this data from another script called 'Player'.
It took me a little while to work this out because it requires specific formatting to tell the engine where to look.
Here's the updated GlobalPlayer script.
Code:
extends Node
var hp_lvl
var shield_lvl
var shot_lvl
var speed_lvl
var rot_lvl
var stats = {
"hull": [6, 12, 18, 24],
"shield": [10, 20, 30, 40],
"shot": [8, 16, 24, 32],
"speed": [150, 200, 250, 300],
"rotation": [0.05, 0.07, 0.9, 0.11],
}
I'm checking to see what the rotation speed of the player is in position 0 of the dictionary's "rotation" array.
Code:
var rot_speed = GlobalPlayer.stats.rotation[0]
Next step: Use the _lvl variables to store the player's level and use that to compare with the position in the dictionary.
To accomplish this, I added these varibles above the Player script and compared them to the GlobalPlayer variables.
Code:
var cur_rot_lvl = GlobalPlayer.rot_lvl
Code:
var rot_speed = GlobalPlayer.stats.rotation[cur_rot_lvl]
It works!