Having some trouble writing a script call

Status
Not open for further replies.

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
This is the script I'm working with:

class Game_Enemy < Game_Battler
  def change_param(param_id, value)
    enemy.params[param_id] = value
  end
end

This is the script call:

$game_troop.members[iD].change_param(param_id, value)

Here was the information the author gave me to work with:

ID: 1, 2, 3,... (in Troops)

param_id: (0 is Max HP, 1 is Max MP)
  def mhp;  param(0);   end               # MHP  Maximum Hit Points 
  def mmp;  param(1);   end               # MMP  Maximum Magic Points
  def atk;  param(2);   end               # ATK  ATtacK power
  def def;  param(3);   end               # DEF  DEFense power
  def mat;  param(4);   end               # MAT  Magic ATtack power
  def mdf;  param(5);   end               # MDF  Magic DeFense power
  def agi;  param(6);   end               # AGI  AGIlity
  def luk;  param(7);   end               # LUK  LUcK

value: the var.

What I'm trying to do is use this script to change the value of parameters for my enemies - but I'm having issues with the syntax and figuring out what symbols carry over and which ones do not when writing the script call.

So if someone could give me a direct example of how to write out this script call to change the mhp of an enemy to variable 1 it would be a big help to me.  Being able to see it as it is actually written in the event would fix my problems I think.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
You'd use this snippet like this:

$game_troop.members[which member? 1-8].change_param(param_id: 0-7, value: any number)The param id corresponds to the list of parameters you have above, 0-7, 6 is agility, 7 is luck, 0 is max health, etc. The value is the number that the parameter should have after the call.

The ID is asking which member of the battle? There can be up to 8 enemies, so you need to choose a number from 1-8, and make sure that enemy is actually in the battle. To make sure they're actually there, use:

Code:
if $game_troop.members[enemy you want] != nil  $game_troop.members[ID].change_param(param_id, value)end
 
Last edited by a moderator:

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
You'd use this snippet like this:

$game_troop.members[which member? 1-8].change_param(param_id: 0-7, value: any number)The param id corresponds to the list of parameters you have above, 0-7, 6 is agility, 7 is luck, 0 is max health, etc. The value is the number that the parameter should have after the call.
For the sake of testing I limited my troop to just 1 type of enemy for now and let's say I'm trying to change mhp of enemy 1 to 999.

This is what I typed:

$game_troop.members[1].change_param

(param_id:0, value: 999)

I got this error:

Unexpected tLABEL

(param_id:0, value:999)

If you could tell me what I did wrong I would appreciate it.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
You don't include the param_id: part, you just use $game_troop.members[1].change_param(0, 999).

Sorry, I should have been more clear.
 
Last edited by a moderator:

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
You don't include the param_id: part, you just use $game_troop.members[1].change_param(0, 999).

Sorry, I should have been more clear.
Np.  I'm new to this scripting stuff so it's probably a challenge slowing down to keep pace with my baby steps.  This is what I typed:

$game_troop.members[1].change_param(0, 999)

Now I get this error:

Script `Game_Interpreter` line1411:NoMethodError occurred

undefined method `Change_param` for nil:NilClass

Any ideas?

Edited#

Noticed I forgot to put my 0, like a dumbass.  But after adding that I still get same error I described. 
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
comment that out (put a # in front of everything) and add this:

puts $game_troop.members[1]and make sure you run the game with a console open (it's under the game dropdown menu in the editor, make sure Console is checked), and then let me know what this prints out.

Edit: also, the error is saying that the method is Change_param. Did you use a lowercase or capital 'C', because that may be the issue here.
 
Last edited by a moderator:

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
comment that out (put a # in front of everything) and add this:

puts $game_troop.members[1]and make sure you run the game with a console open (it's under the game dropdown menu in the editor, make sure Console is checked), and then let me know what this prints out.

Edit: also, the error is saying that the method is Change_param. Did you use a lowercase or capital 'C', because that may be the issue here.
I used a lower case c.  Does it need to be capitalized?  I checked Show Console like you said.

This is what I typed on this attempt, and I'm just copy/pasting from the script on the event itself so everything should be exactly as I wrote it on the game:

#puts $game_troop.members[1].change_param(0,

999)

Now I'm getting this error:

Script 'Game_Interpreter' line1411:SyntaxError occurred

unexpected ')', expecting $end
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
nono, I meant do this:

Code:
#$game_troop.members[1].change_param(0, 999)puts $game_troop.members[1].inspect
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
nono, I meant do this:

#$game_troop.members[1].change_param(0, 999)puts $game_troop.members[1].inspect
Ok I did this:

#$game_troop.members[1].change_param(0, 999)

puts $game_troop.members[1].inspect

This didn't give me any errors, but enemy1's MHP didn't change into 999.  Is the 999 an actual amount or is it the variable ID?
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
Did you see what was printed to the console? That wasn't supposed to change the health, because we commented it out, so it's not run. The '#' tells ruby to ignore this.
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
Did you see what was printed to the console? That wasn't supposed to change the health, because we commented it out, so it's not run. The '#' tells ruby to ignore this.
Oh, it says:

Nil

_
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
try without the [1], so

Code:
puts $game_troop.members.inspect
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
try without the [1], so

puts $game_troop.members.inspect
Did this:

#$game_troop.members[1].change_param(0, 999)

puts $game_troop.members.inspect

If you need me to increase the picture size just let me know and I'll try to resize it.

 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
Ahh, your troop only has one enemy in it (and I forgot that $game_troop is a normal array, unlike $game_variables), so use the change_param on $game_troop.members[0]
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
Ahh, your troop only has one enemy in it (and I forgot that $game_troop is a normal array, unlike $game_variables), so use the change_param on $game_troop.members[0]
Are you wanting me to repeat the earlier process after changing the [1] to [0] then show you what the console says?

Or are you meaning you want me to remove the comment symbol and the second line and just try writing the script call as:

$game_troop.members[0].change_param(0, 999)
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
Nope, just $game_troop.members[0].change_param(0, 999) should work for you. 
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
Nope, just $game_troop.members[0].change_param(0, 999) should work for you. 
Cool it's working now, tyvm.

If I was to want to change the MHP to a specific variable rather a number how would I type that?  Maybe this?  change_param(0, [159])  
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
it wouldn't fit easily in the script box, because of how they work. what you'd have to do is something like

val = $game_variables[my variable id]if $game_troop.members[0] != nil $game_troop.members[0].change_param(0, val)endIf a line goes off the edge of a script box and wraps around to the next line, it completely breaks the script, so you have to use variables to make it all fit sometimes.

but anyway, just put a number where it says [my variable id], and it'll give you that variable. Remember, game variables start at 1, not 0.
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
it wouldn't fit easily in the script box, because of how they work. what you'd have to do is something like

val = $game_variables[my variable id]if $game_troop.members[0] != nil $game_troop.members[0].change_param(0, val)endIf a line goes off the edge of a script box and wraps around to the next line, it completely breaks the script, so you have to use variables to make it all fit sometimes.

but anyway, just put a number where it says [my variable id], and it'll give you that variable. Remember, game variables start at 1, not 0.
Thanks for all the help, appreciate it.
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
no problem :) . That if statement I put in there should prevent issues like this again, mostly. It won't crash the game, but it won't work if the enemy is nil (nothing, null, doesn't exist).
 
Status
Not open for further replies.

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,862
Messages
1,017,049
Members
137,570
Latest member
fgfhdfg
Top