Results 1 to 4 of 4

Thread: csv and while loop

  1. #1

    Default csv and while loop

    I have been struggling with a script freezing and don't know why.
    I have been experimenting with csv files to store information - like scrolls I have saved and gems I am hoarding.

    My script has been slowing when I get to this loop, essentially no game data goes through once I do this but I can enter commands but can't see what happens.

    while line = get
    if line =~ /ACCEPT/
    fput "accept"
    fput "wear pouch"
    break
    end
    end

    I am not concerned there is a problem with the loop, because when copied and pasted into a test script in isolation and it works fine. It is freezing this script in the game. If I kill the script the game goes back to working normally.

    I think this problem may be caused by my use of a csv file. I have a few lines in the script that may be causing problems and wonder if anyone has any idea how I might fix this.

    1.
    require 'csv'
    get = CSV.read('hoardgem.csv') #this is a file of #_of_gems and gem_name

    2. also I have created a string to use in a regular expression (I need these to be available as an array but also as a string for regular expression search).

    get_gems = ["gem_name", "another_gem_name", "ect"]

    @gems_to_hoard = ""
    get_gems.each do |obj|
    if @gems_to_hoard.empty?
    @gems_to_hoard = obj
    else
    @gems_to_hoard = @gems_to_hoard + "|" + obj
    end
    end

    #this should yield "gem name|another gem name|ect"

    As I say all the other code seems to work fine. It is simply the while line = get part that freezes. I appreciate any thoughts.

    Ryaden

  2. #2
    Join Date
    Mar 2008
    Location
    Virginia, USA
    Posts
    287

    Default

    Try using a different variable name than get for your CSV file read. get is a function within lich so perhaps it's doing something funky there.

    Besides that I'm not sure what to tell you without seeing the actual code. I'm also typing this while trying to fall asleep, so you have that working against me too.
    Websites
    Lich Wiki Info
    EO Scripts Github Repository - Collaborative script development by the community.
    EO Lich5 Github Repository - Collaborative Lich Development for GS4 & DR for modern Ruby.
    Elanthia Online Forums Archive

    Player of Tysong

  3. #3

    Default

    Choose another variable name is right, since you're actually masking the get method that you want to use later on. On a different note, what you're doing in section two can be replaced with
    @gems_to_hoard = get_gems.join("|")
    No need to build it concatenate by concatenate yourself.

  4. #4

    Default

    Thanks so much. It turns out the get = was the problem in the script. Still learning these small details that can cause problems. I appreciate the thought on .join as well. Just started learning less than a year ago, so I enjoy learning more efficient methods.

Similar Threads

  1. script loop help
    By gnikoa in forum The Lich Project
    Replies: 0
    Last Post: 05-25-2020, 01:34 PM
  2. Axe Loop
    By Pin in forum Wanted
    Replies: 0
    Last Post: 02-09-2020, 10:57 PM
  3. Replies: 12
    Last Post: 12-21-2015, 01:04 AM
  4. Looking for a sheath, axe loop, etc..
    By Izadriel in forum GSIV Merchant's Market
    Replies: 0
    Last Post: 09-08-2004, 08:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •