Jump to content
Sign in to follow this  
O.P. Wilkituska

Adding items by variable

Recommended Posts

Hi, again!
 
I'm trying to develop some kind of system to give loot based on the value of a variable. I was quite dissappointed to discover that I can use variables to specify the amount of items a chest contains, but not the ID of those items... I know almost nothing about scripting, but I've been reading about  script calls, and I found this two codes:

This is the script call to give items to the player:

$game_party.gain_item($data_items[n], amount)

 
And this is how you reference a variable:
$game_variables[n]

 
My question is: will this work?
 
$game_party.gain_item($data_items[$game_variables[1]], 1)

 
What I'm trying to do with that code is giving the player one item, being that item the one whose ID is the same as whatever is the number stored in variable #1. So, if variable 1 equals 5, and the 5th item in the database is a mana potion, the player will get a mana potion.
Is that correct? If not, how can I use a variable (or a formula) to give items to the player? If yes, is there anyway to display that item's name in a message (as in "You got a mana potion!")?

Thanks in advance! Edited by O.P. Wilkituska

Share this post


Link to post
Share on other sites

$game_party.gain_item($data_items[$game_variables[1]], 1)

This will give you one of the item type item with the id of game variable 1.

 

To display the item simply make this script call:

$game_message.add("You got a #{$data_items[$game_variables[1]].name}")

Share this post


Link to post
Share on other sites

Thanks, but it seems that the syntax is not correct. I tried some variations of the same idea, but none worked. You simply can't use $game_variables[1] in the place of n.

If someone knows a way to work around this, please let me know!

Share this post


Link to post
Share on other sites

Uhh dude... yes you can. Of course you have to set the variable to something higher than 0 for it to work. I just tested it and it worked like a charm. Set variable 1 to 5, get an item of id 5 and a message pops up with the name of the item.

 

Have you initialized the variables first?

Script call to initialize a variable:

$game_variables[n] = true/false

 

I have already created a chest randomizer myself if that's enough to make you trust me.

Edited by Nataxinus

Share this post


Link to post
Share on other sites

Of course, yes, I assigned a value to that variable beforehand. I don't know why that doesn't work for me, but I tried other methods until I found one that works.

This is what worked for me:

 

n = $data_items[$game_variables[1]]

$game_party.gain_item(n, 1)

Edited by O.P. Wilkituska

Share this post


Link to post
Share on other sites

$game_party.gain_item($data_items[$game_variables[1]], 1)

is the same as your method.

You just set a local variable there to the value of $data_items[$game_variables[1]].

It works, you probably just wrote it wrong missed a parenthesis or bracket.

Your syntax there is correct, now try replacing n with $data_items[$game_variables[1]]

Share this post


Link to post
Share on other sites

I can tell you that one works for me and the other does not. It's not a misspelling. I wrote it several times and even copied and pasted it from your post. It seems that the problem is simply that the one-line code is too long and gets cut off. I've seen people experiencing this same problem, so maybe it has something to do with the software version (I've installed and unofficial patch to translate it to my native language, tho). There's no need for any other modification, since my method already works, so this request is pretty much solved.

I could try if the one-line code works with the "everything official version" of Ace if someone is curious about it, but, for me, this thread can be closed now.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted