Use a variable as an id?

● ARCHIVED · READ-ONLY
Started by Manu_Sensei 13 posts View original ↗
  1. Hello everyone.

    I'm creating a game which has 4 different ends.

    The end you will see depends on how many secret diaries you have collected during the game.

    I'm using a simple variable called nDiaries.

    Every time the character reads a diary, it launches a common event in which he reads what is written on it.

    There are 20 diaries, 20 common events.

    What i'm trying to do is to call a common event DEPENDING on that "nDiaries" variable.

    So if you picked the diary #1 You launch Common Event 1. If you miss Diaries #2 and #3 and you pick #4 you launch the Common Event 2 as the nDiaries is = 2.

    In conclusion, what i'm trying to do is:

    #game_temp.reserve_common_event( nDiaries )

    I've tried

    #game_temp.reserve_common_event( \v[2] ) and

    #game_temp.reserve_common_event( $game_variables[2] )

    but they don't work.

    Can you help me?

    Thanks! :D
  2. #game_temp.reserve_common_event( $game_variables[2] )

    ??

    why you have # in front of game_temp... it should be $game_temp :D .

    i think it should be this one:

    $game_temp.reserve_common_event( $game_variables[2] )

    # is for commenting scripts. :D .
  3. That was a mistake writing here.

    In the game I'm using $game_temp.reserve_common_event( $game_variables[2] ) and it doesn't work. :(

    This is what i do. 

    I use an script and all what is in it is 

    $game_temp.reserve_common_event( $game_variables[2] )

    That's it. That should do it, doesn't it? or do i have to add more information? :/
  4. I've figured out that the main character is getting, for example, Diary 1, i skip two of them and then i get Diary 4, but what i should get is Diary 2.

    So, doing a little bit investigation i found i can use this:

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

    So, what i'm tring to do is:

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

    but it doesn't work either :v

    I'm frustrated
  5. Manu_Sensei, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


    What do you mean "it doesn't work"? What DOES happen? Do you get an error? Does ANY common event run?


    Sounds like your variable is being incremented too often.
  6. Shaz said:
    Manu_Sensei, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.

    What do you mean "it doesn't work"? What DOES happen? Do you get an error? Does ANY common event run?

    Sounds like your variable is being incremented too often.
    I get an error everytime.

    No common event runs at all. 

    http://imgur.com/9WYC

    http://imgur.com/T2oW0PF

    Sorry for double posting, I'll delete one of them.
  7. you can't delete them - only mods can :) Just edit your last post next time.


    See, by providing the error, you actually allow us to help you.


    The error message tells you EXACTLY what's wrong. On your second command, you've put ]] where you only need ]


    However, that has nothing to do with which item is gained, the fact that it's given you diary 4 instead of 2, or that it's not calling the right common event.


    So fix that error and see if it flows through to make everything else work correctly, and if it doesn't, tell us what IS happening rather than what ISN'T happening, and we'll see if we can get you any closer. ;)
  8. Ok, so i've tried again and i'm still having that mistake.

    I've used a variable for the diaries found (in order to take Diary 1, Diary 2...)

    I want to gain an object depending on that value, so the script should be:

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

    where $game_variables[2] should be that variable. For example, if $game_variables[2]==2, it shoud call the Item 2 from the database and add 1.

    Now, for the common events i'm using this script:

    $game_temp.reserve_common_event( $game_variables[2] )

    so if $game_variables[2]==1 it should call the common_event 1, shouldn't it?

    and this is the error I get

    http://imgur.com/UDCoiKq
  9. Do you actually READ the error messages? It is saying you have not passed an argument when one was expected.


    Remember to show us new screenshots when you change your event. AS you've seen above, retyping it here will introduce (or leave out) errors that you've actually made, and not give us all the correct information.


    Based on your first screenshot (though it's probably changed since then), try putting $data_items[ on the first line instead of just $data_items
  10. Can you read the diaries again after you get them?

    Also, I don't know why you're trying to do this via scripting when regular eventing should be able to handle it.
  11. If you're just picking up short diaries, I would do it with ONE common event, unless there's something fancy happening that we don't know about. For instance, you could do it like this:

    EVENT FOR 3RD DIARY

    diary = 3

    call common event [diary]

    DIARY COMMON EVENT

    if diary = 1

    show text "TEXT HERE"

    if diary = 2

    show text "TEXT HERE"

    if diary = 3

    show text "TEXT HERE"

    So you'd just set the variable "diary" each time, and call the common event. Then the order doesn't matter. Again, this assumes that's all that happens. If you want the player to be able to read them again later, then this wouldn't be enough. But it seems like you're overcomplicating it.
  12. @tommy Gun, I think the problem with that is that he wants the second diary available no matter which diary is found second.

    I think if I were implementing this from scratch, I would have done this:

    make a switch for every diary
    DiaryOne Found, DiaryTwo Found, etc. (you may not need the switch depending on how you implement. This is only necessary if you can find the diaries multiple times.)

    Make a variable for every diary
    DiaryOne Message, Diary Two Message
    And for the total number of diaries found so far.
    Total Diaries Found

    When the diary is found, increment Total Diaries Found to total diaries found plus one.
    then assign the variable Diary(whatevernumberyoufound) Message to Total Diaries Found.

    Then you can use TommyGun's idea for reading the message based on whichever diary was found in whatever order.


    So if you find Diary ten first, the value of DiaryTen Message would be one, and the common event would need that variable amount to know what message to show. I guess you'd need one more variable, Message number or something, to pass the value to the Common Event. So that would be the common event particular to this diary - A common event which assigns Message Number the Value of Diary(Whatever) Message.

    And then only one more common event with a conditional branch called by all of the diaries.

    Not as elegant as your way, perhaps.

    But it would effectively do this:

    Manu_Sensei said:
    What i'm trying to do is to call a common event DEPENDING on that "nDiaries" variable.
     
    So if you picked the diary #1 You launch Common Event 1. If you miss Diaries #2 and #3 and you pick #4 you launch the Common Event 2 as the nDiaries is = 2.
    Hope my perspective helps.
     
     
    *****EDIT******
     
     
    Well, I tried to implement this and I am having trouble getting the item to call two diffferent common events, so maybe one will have to call the other or maybe my idea won't work but I thought it was only fair to let you know!
     
    Good luck!
  13. Oh, you're right, I misread it. Well I'd still do it the same basic way, but just +1 the variable each time:

    Code:
    EVENT FOR EVERY DIARYdiary +1call common event [diary]DIARY COMMON EVENTif diary = 1show text "TEXT HERE"if diary = 2show text "TEXT HERE"if diary = 3show text "TEXT HERE"