Help running a command through a script

Untitled-1.png


All I want to do is set the variable to the player's current hp. I was able to do it with "$game_variables[11] = actor.hp", however it lagged the game pretty hard. Here's the thing: I don't even need to have it updated every frame, which is what I believe that was doing. I just want to use it on a def initialize, but when I try to, I get an error that "actor.hp" cannot be read.

EDIT: The picture is just to show the command I want to run through a script. Sorry if that might have been confusing.
Spoiler: old text
Regarding MV about Command's:
(sry i got no idea on Ruby and RGSSx ,but i believe it should work similar, i just dont know the exact Code)

Commands can be used via Script using the Command Nr but i dont know most Numbers of most Commands and cant explain that more detailed,sry.

But "$game_variables[]" as well as "gameSwitches" can be set via script without using the Command Nr.
In MV for example you can use:
JavaScript:
 $gameVariables.setValue(varID, value);

here some links for MV if ever needed:
Usefull Scriptcalls Info (Page is not made by me)
alternative Scriptcall List (Page is not made by me)
perhaps you can find such a scriptcall list for Ruby and RGSSx somewhere,..

Im am sorry if that doesnt solve your Question, i recognized the topic Ruby and RGSSx when my message was already half done.
And since nobody else answered i hoped that this could help
Edit
here the scriptcall list related topics for Ruby and RGSSx which i could find.
-Set Variables equal to amount of Items

-Script Call Equivalents of Events Doc

-Slip into Ruby: An introductory guide to RGSS for beginners.

-Here the VX-Ace Script Call List:
Spoiler: Img from VX Ace List-Link
Screenshot_6.png
https://forums.rpgmakerweb.com/index.php?threads/script-call-collection-for-vxace.25759/
( i copy pasted this Link from here #3 )

perhaps these links are more helpfull
I just want to use it on a def initialize, but when I try to, I get an error that "actor.hp" cannot be read.
It depends on where you try to do that. You could put it into an update method that will only execute every x-amount of frames for example. In the best case you change the value at the exact point it's necessary to avoid any lag. To help with that it would be good to know what you're trying to do with it, aswell as where you tried to set the value (the point that got you the error).
however it lagged the game pretty hard.
the command itself cannot create any lag.
The only way it can lag is if you place it in the wrong context like a parallel process without waits.

and the same goes for the script variant - the error you received also looks as if you placed the script line into the wrong context.

So I think nothing is wrong with the command itself, you need to tell us what you want to use it for and where before we can tell you the correct form of using it.
here the scriptcall list related topics for Ruby and RGSSx which i could find.

I went through all the command script calls before making my post, however the "-Set Variables equal to amount of Items" is close. I attempted to use "$game_var... = $game_party.members[0].hp" before my post as well, but that yielded nothing; the variable stayed 0.

To help with that it would be good to know what you're trying to do with it, aswell as where you tried to set the value
So I think nothing is wrong with the command itself, you need to tell us what you want to use it for and where before we can tell you the correct form of using it.

Understood! Sorry for the lack of context. I somewhat assumed the issue was a simple lack of knowledge on my part, just not knowing the exact line of code or terms I should use. No matter, here's some more info.

So I'm currently using the Sapphire Action System, however it has been edited greatly. I've added melee spells, heals, buffs, etc as real time skills you can use, rather than just projectiles. To do this, I've given the skills an ID number in the note section. When the Sapphire_Skill is initialized (whenever a skill is cast,) the game goes through a number of if, elsif, esif, for all the spells in the game, where it gains it's certain traits. For buffs and the like, I cut the middle-man and just tell the game what animation to play, and what to do.


elsif ID == 2
$game_player.instance_eval("@move_speed = 5.0")
$game_player.animation_id = 123

Something like this ^^^

So, I've designed a healing spell that increases in strength the lower you are on health.


hcheck = $game_variables[8]
$game_variables[41] = hcheck * 0.1
$game_variables[42] = hcheck * 0.2
$game_variables[43] = hcheck * 0.3
$game_variables[44] = hcheck * 0.4
$game_variables[45] = hcheck * 0.5
$game_variables[46] = hcheck * 0.6
$game_variables[47] = hcheck * 0.7
$game_variables[48] = hcheck * 0.8
$game_variables[49] = hcheck * 0.9
#---
if ID == 4
if $game_variables[11] <= $game_variables[41]
$game_variables[50] = hcheck * 0.3
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[42]
$game_variables[50] = hcheck * 0.28
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[43]
$game_variables[50] = hcheck * 0.26
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[44]
$game_variables[50] = hcheck * 0.24
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[45]
$game_variables[50] = hcheck * 0.22
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[46]
$game_variables[50] = hcheck * 0.20
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[47]
$game_variables[50] = hcheck * 0.18
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[48]
$game_variables[50] = hcheck * 0.16
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[49]
$game_variables[50] = hcheck * 0.14
$game_party.members[0].hp += $game_variables[50]
elsif $game_variables[11] <= $game_variables[8]
$game_variables[50] = hcheck * 0.12
$game_party.members[0].hp += $game_variables[50]
end


Variable 8 = Max HP
Variable 11 = Current HP
Variable 50 = Heal based on level, sorta, still workin that, so don't worry about it


Keep in mind, all of this is happening in the initialize. It makes it so the game only has to read this if the skill is cast, which would be the perfect place to update the current health. So, I insert

$game_variables[11] = actor.hp
$game_variables[8] = actor.mhp

at the very top, run the game, try to use a skill, and
help.png


Ouch.

And I can't for the life of me figure out why. Like I said, it functions when put in the update def of the very same class.

You could put it into an update method that will only execute every x-amount of frames for example.

Not sure what you mean by this, but I would love to know, not just for this problem, but for future reference as well.

Ok, sorry that was long. Hope I didn't include too much unnecessary information, and thank you all for your time in helping me with my silly game. It means a lot 😀
And I can't for the life of me figure out why.
the reason is that the variable actor simply didn't exist at that moment. Actors (and most of the other game data) are only defined on "new game", any call to them before the new-game-sequence is completed (like trying to access that data while still on the title screen) will result in that error.

And that is exactly what I assumed when you said you got an error with that and why I asked for context - you tried to access that data before it exists.

Unfortunately I don't know enough of that script (especially not if it is already modified) to tell you where you have to place the line, but it has to be in the action execution part, long after everything is initialised.
it has to be in the action execution part, long after everything is initialised.

That's the thing, it totally is though. This error occurs after getting in the game, running around my test area, unlocking the skill, then right as I hit the button, the error occurs. I can go take damage from test enemies, use health items, etc, waaaaay before the error, so the game has to have the information somewhere.

The initialize I'm talking about initializes one single skill at a time, unless I'm misinformed. I'm thinking on the spot here, but is it possible that the script initializes all of this code before the game starts, but doesn't execute it until told to do so? If I throw a random "Var + 1" in there, for example, that code is being read at the title, but I don't see the variable increase until I hit the button?

I have a few ideas to test out now, so I appreciate the reply. Any further posts would be helpful, and I'll post back here if I find a solution.
I can't for the life of me figure out why.
Is that code you are using for the actor.hp in the class Sapphire_Skill section?
If so then the error is from that class not having any reference to actor. But I see in the code that this section has @char as a reference to events or player.
So you should just need to use
$game_variables[11] = @char.hp
$game_variables[8] = @char.mhp
So you should just need to use

nope.png


Still an error from that one.

If so then the error is from that class not having any reference to actor.

This can't be true. I used " $game_variables[11] = actor.hp, etc" in the update of the same class, and it functioned, however, lagged the game, as it was executing every frame. I do notice the "char" references now, though. Perhaps I could add the player health information in using this method? I'll keep this in mind.
I think I've got it.

I found the part of SAS that was using player health (dealing damage and whatnot) It was using Game_Player > Game_Character as it's class.

Changed class Sapphire_Skill

to

class Sapphire_Skill < Game_Player

actor.hp term works fine. This might even open up some new options for me in designing skills. @Roninator2 you seem to know more than me, so if this is a bad idea, let me know haha. Otherwise, I think I'm all good. Thanks for your help everyone!

Original thread: https://forums.rpgmakerweb.com/threads/help-running-a-command-through-a-script.129737/