new to ruby...need For loop advice

Discussion in 'Learning Ruby and RGSSx' started by iNBee317, Jun 11, 2014.

Thread Status:
Not open for further replies.
  1. iNBee317

    iNBee317 Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    I am trying to create a system in game similar to pathfinders skill checks (perception, acrobatics, climb). I am using PK'8s data suite to store the ranks players add to these skills and have the system add their corresponding parameter(atk,def,etc.), skill rank, and the result of a d20 dice roll.

    As of right now I have been doing this the long way with a common event containing conditional branches that determine if the actor is in the party or not, then calculates their score and compares it to the DC of the event which flips a switch that tell the event (say a trap) whether the actor succeeded or failed.. This is a lot of redundant work. So I am trying to figure out the way to create a 'For' loop where it replaces a placeholder in my script with a number N where N is the actor value. each time the loop run N changes to the actor value for the actor next in my party. That way I don't have to copy, paste, and edit fields for each specific actor and end up with countless conditional branches. 

    I could post my current event and common event though I don't think it will help much since I am going for a complete overhaul.
     
    #1
  2. RyokuHasu

    RyokuHasu Developer Veteran

    Messages:
    274
    Likes Received:
    37
    Location:
    Nebraska
    First Language:
    English
    here is a simple for loop for Ruby

    Code:
    for i in 1..5   puts "Value of local variable is #{i}"end
     
    Last edited by a moderator: Jun 11, 2014
    #2
  3. iNBee317

    iNBee317 Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    z=$game_variablesfor i in 0..z[37] x=$game_party.members[#{i}].id z[9]=$game_actors[x].mdf z[9]+= actor_self_variable(x,"acr") z[9]+=z[14]end

    Anyone know what I am doing wrong here? It says unexpected tIDENTIFIER, expecting ']'
     
    Last edited by a moderator: Jun 11, 2014
    #3
  4. iNBee317

    iNBee317 Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    I did not resolve the 'for' loop issue though found another way to go about it. 
     
    #4
  5. Shaz

    Shaz Veteran Veteran

    Messages:
    37,349
    Likes Received:
    11,146
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    iNBee317, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


    Does it tell you which line is causing the issue?


    Try putting some spaces in there - in most cases it'll make it more readable - but sometimes it solves errors.


    Also, you don't need [#{i}] - just do
     
    #5
  6. Mithran

    Mithran Global Moderators Global Mod

    Messages:
    404
    Likes Received:
    212
    First Language:
    English
    Incidentally, the reason the above didn't work (assuming the position it was used in was correct) was that the unnecessary # commented out the rest of the line, including the right closing bracket, which is exactly what the error was saying.
     
    #6
    PK8 and Shaz like this.
  7. iNBee317

    iNBee317 Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    Thanks everyone this was very helpful!
     
    #7
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    37,349
    Likes Received:
    11,146
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
     
    #8
Thread Status:
Not open for further replies.

Share This Page