Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

XAS Weapon's tool = a variable. Is this possible? [Resovled]

Okay so I came up with a great idea were an weapon's tool in XAS is equal to a variable.
It comes up with an error:
Script "XRXS - XAS"  line 122: NoMethodError occured.
undefined method '[]' for nill:NilClass
The code:
Code:
# Definição de qual ferramenta será
# ativada quando equipar a arma.
#
# WEP_ID_TOOL = { A=>B, A=>B, ...}
#
# A = ID da Arma. Thats the weapon
# B = ID da Ferramenta. Thats the tool that the weapon uses.
WEP_ID_TOOL = {
#   A  B    Weapon Name       
    1=>1, # Bronze Sword     
    2=>2, # Fire Sword      
    3=>3, # Light Sword      
    4=>4, # Dwarf Axe        
    5=>5, # Wizard Staff    
    6=>6, # Elf Bow          
    7=>7, # Disc             
    8=>$game_variables[1] #line 122
    }
The reason i want this is becuase you can make weapons upgradeable by changing the variable tool for the weapon.
AND you can put the same variable for 10 weapons and make it a profiencieny.
If anybody can help me, please do!
 
It's just how the game variables works. This might work better if you do it more like the following

Code:
# Definição de qual ferramenta será
# ativada quando equipar a arma.
#
# WEP_ID_TOOL = { A=>B, A=>B, ...}
#
# A = ID da Arma. Thats the weapon
# B = ID da Ferramenta. Thats the tool that the weapon uses.

$toolONE = $game_variables[1]

WEP_ID_TOOL = {
#   A  B    Weapon Name       
    1=>1, # Bronze Sword     
    2=>2, # Fire Sword      
    3=>3, # Light Sword      
    4=>4, # Dwarf Axe        
    5=>5, # Wizard Staff    
    6=>6, # Elf Bow          
    7=>7, # Disc             
    8=>$toolONE
    }

I don't know if it will work right, I can't pull up an XAS right now. If it dosen't work, try to just set the $toolONE to a number. You can easily control the variable via a script call. If all else fails, I'll see what I can do in the morning. I'm getting good at working with XAS. This is a great idea, and I'd be glad to see it working.
 
same error but on the line that says
$toolOne = $game_variables[1]
I took out that line just to try, it works but i can't attack with a tool.

Okay even though i don't know how to script, i tried something new, $tool1 = 36
It works, and tool 36 comes out, but i do not know how to increase it or put a condtional branch that says
if $tool1 > 37
 
For eventing you mean? That's simple. If you want to check if a script variable is equal to something, you go to the script tab in the conditional branch, and enter

$tool1 == 36

that would be to check if $tool1 is equal to 36

$tool1 != 36

that's not equal to 36

$tool1 < 36

that's greater than 36

$tool1 > 36

that's less than 36!

It's quite simple, I love that they allow you to combine eventing and scripting together in RMXP. I don't know how to script either, I can just mess with other's scripts somewhat.
 
okay so now i've got this
Code:
# Definição de qual ferramenta será
# ativada quando equipar a arma.
#
# WEP_ID_TOOL = { A=>B, A=>B, ...}
#
# A = ID da Arma.
# B = ID da Ferramenta. 
$tool1 = 36

WEP_ID_TOOL = {
#   A  B    Weapon Name       
    1=>1, # Bronze Sword     
    2=>2, # Fire Sword      
    3=>3, # Light Sword      
    4=>4, # Dwarf Axe        
    5=>5, # Wizard Staff    
    6=>6, # Elf Bow          
    7=>7, # Disc             
    8=>$tool1
    }
But for somereason when i put in the script in the events
Code:
$tool1 += 1
It doesn't want to work. It keeps at the same tool.
 

khmp

Sponsor

I'm afraid Ruby doesn't do postfix/prefix notation. One of the C features it didn't copy.

Good news is that I can tell you why it keeps the same tool. That constant is only read one time. WEP_ID_TOOL I mean. You need to manipulate a more dynamic source. Possibly somewhere inside the class that reads this data. Or is this constant have global status as well? Meaning it isn't inside a class definition.

If it does have global status, (not defined inside a class)
Code:
$weapon_tools = 
{
  #   A  B    Weapon Name
  1=>1, # Bronze Sword
  2=>2, # Fire Sword
  3=>3, # Light Sword
  4=>4, # Dwarf Axe
  5=>5, # Wizard Staff
  6=>6, # Elf Bow
  7=>7, # Disc    
  8=>$tool1
}

And to change the value of a particular weapon you need to know what index inside the hash leads to what weapon. To change the Elf Bow for example you would do "$weapon_tools[6] = new_value". I hope that helps you out Bullet_Darkness.
 

khmp

Sponsor

Sure I'll try. In Ruby there are different types of variables. The first you have up there are globals. Globals are variables preceded by a "$". You made a global called "$tool1" and set it equal to 36. Globals can be accessed anywhere from within RMXP. Then after that you made a constant. A constant is made by giving the first letter of it's variable name a upper case letter. The constant you made was called "WEP_ID_TOOL". Constants are called constants because they can't be altered after initial declaration. Of course thats a lie but you should act like it isn't. These guys however have different levels of access depending on where they are declared.

And I'm sure I did a crummy job with that so go here if you are still confused on the matter:
http://s11.invisionfree.com/The_Venedia ... ntry270018

Here's how this applies to your situation. The compiler, whatever reads the lines of code and interprets them, reads the script line by line. It skips comments and then reaches a global and sees it is initialized to the value 36, $tool1. Then the compiler reaches your constant, "WEP_ID_TOOL", sees it is reading a hash and initializes all the keys, those are the values before the "=>", and ties the keys to values, whatever comes after the "=>". Your $tool1 variable is seen and copied, that's all. It doesn't maintain a pointer to the variable. So after reading/initializing the constant hash, it is done with it. Changing the global "$tool1" will not affect the anything in the constant because it has already been read once. In fact even if "WEP_ID_TOOL" was not a constant you would still have this problem. Because for the same reason above, it is only initialized once.

Your answer is one of the following.
1.) Manipulation of a global hash like I made.
2.) Create a class that encapsulates a hash. Use the class to manipulate this hash.

There are probably other answers but those are probably the easiest to implement. My problem is that I have no idea what scripts these are interacting with. So I'm at a loss as to how to really help you with this. I tried searching for XAS Weapon's Tool and didn't find anything but this topic. Or is this the whole script and you made it?
 
I tried searching for XAS Weapon's Tool and didn't find anything but this topic. Or is this the whole script and you made it?
It's XAS, an abs with tools. It was submitted recently in the script section. I am not a very good scripter, barely know anything(I wouldn't be able to make a box appear on the screen). The tools in XAS are made in events on map 1 and i was wondering if i could change the tool the weapon uses by changing a variable, like $game_variables[1]. But it came up with an error.
The thread to it.
http://www.rmxp.org/forums/index.php?topic=36855.0
and the place where i downloaded it from.
http://www.atelier-rgss.com/RGSS/Battle/XAS_00a.html
 

khmp

Sponsor

That is a neat system. Ok here's what I tried.

Open your script editor, F11. Go into the script, "XRXS - XAS", rename WEP_ID_TOOL to this $weapon_tools. Then fly down to line 1941, those are numbers on the left side of the right panel, change that line to this, weapon_tool_id = $weapon_tools[weapon_id]. Now to change a tool assigned to weapon do this:
Code:
# weapon_id - the id of the weapon you are trying to change.
# new_tool - the id of the tool to be used when the weapon is activated.
$weapon_tools[weapon_id] = new_tool
You can do that through an event if you want using "Script...".

Good luck with it Bullet_Darkness! :thumb:

If you have any further questions on it just ask.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top