Dostring Lua Formatting - multi-line , ";" required? menu

User Tag List

Results 1 to 5 of 5
  1. #1
    mongoosed's Avatar Member
    Reputation
    1
    Join Date
    Feb 2007
    Posts
    55
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dostring Lua Formatting - multi-line , ";" required?

    My question is regarding the proper formating when writing to framescript execute (dostring) for multi-line lua executions. I have seen slightly conflicting examples around here and I just wanted to be clear on how formatting should be done properly.

    The best example I have seen of a long mutli-line string is as follows:
    if (AccountLoginUI and AccountLoginUI:IsShown()) then AccountLoginUI:Hide(); DefaultServerLogin('" + username + "', '" + password + "'); elseif (RealmList and RealmList:IsShown()) then for i = 1, select('#',GetRealmCategories()) do for j = 1, GetNumRealms(i) do if (GetRealmInfo(i, j) == '" + realm + "') then RealmList:Hide(); ChangeRealm(i,j); end end end elseif (CharacterSelectUI and CharacterSelectUI:IsShown()) then for i=0,GetNumCharacters() do local name = GetCharacterInfo(i); if (name and name == '" + charname + "') then CharacterSelect_SelectCharacter(i); end end EnterWorld(); end

    As you can see, ";" is used in many places. However, reading through the LUA documentation and from comments in some of the LUA irc channels, usually the ";" isn't neccessary. Therefore, would this string be valid when passed using dostring?

    "if UnitHealth(\"player\") >= 4 then testVal = 111 end for i = 1, GetNumPartyMembers(), 1 do if UnitHealth(\"party\"..i) >= 3000 then testVal = 555 else testVal = 222 end end end"

    Perhaps it is being sending in "end" statements break the localized string in some way? I am sorry if this question has been answered before.

    Ideas?

    **as a side note, has anyone tried working arrays into their dostring?
    Last edited by mongoosed; 12-14-2010 at 03:01 AM.

    Dostring Lua Formatting - multi-line , ";" required?
  2. #2
    opulent's Avatar Member
    Reputation
    5
    Join Date
    Apr 2009
    Posts
    29
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your lua looks wierd man, read up a little on lua syntax and write it out properly using indentation before you inject it. This way you'll understand what's going on better

    This is what I think you meant to do (untested)
    Code:
    string lua = 
    
    @"
    if UnitHealth(""player"") >= 4 then 
    	testVal = 111; 
    end 
    
    for i = 1, GetNumPartyMembers(), 1 do 
    	if UnitHealth(""party""..i) >= 3000 then 
    		testVal = 555; 
    	else 
    		testVal = 222; 
    	end 
    end
    ";
    
    Lua.DoString(lua);
    You had an extra end tacked on there

    Lua 5.1 Reference Manual

  3. #3
    mnbvc's Avatar Banned
    Reputation
    120
    Join Date
    Jul 2009
    Posts
    273
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you never need a ;

  4. #4
    mongoosed's Avatar Member
    Reputation
    1
    Join Date
    Feb 2007
    Posts
    55
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks for the feedback. I saw the ";" used in some examples from apoc's dostring code and so i thought that for some reason it was mandatory for proper execution. Thank you guys. (also about the extra end... thanks for catching that. ) By the way.. I was unable to pass an array out using localized string.. have you folks had any success passing out arrays using dostring and localized string?

  5. #5
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mnbvc is correct: You never need ";" in Lua. Syntactical beginning ("while" "for" "if" "else" etc.) and "end" demarcate code blocks precisely.

    ";" is just parsed to a no-op.
    Don't believe everything you think.

Similar Threads

  1. Quotes from Steven Write
    By Amedis in forum Community Chat
    Replies: 2
    Last Post: 11-14-2022, 10:26 AM
  2. I thought what I'd do was... (Post great quotes or lines)
    By ßetray in forum Community Chat
    Replies: 2
    Last Post: 09-17-2009, 04:19 PM
  3. WTB Powerleveling - Need Quotes!!
    By Drovos in forum Members Only Gold And Powerleveling Buy Sell
    Replies: 7
    Last Post: 10-14-2007, 10:26 AM
  4. Quote: For a Steam Account!
    By Obama in forum Members Only Accounts And CD Keys Buy Sell
    Replies: 0
    Last Post: 09-16-2007, 07:57 PM
  5. Funny GM quotes
    By shadowfox47 in forum World of Warcraft General
    Replies: 9
    Last Post: 08-13-2007, 07:24 PM
All times are GMT -5. The time now is 02:23 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search