[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  String Manipulation
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: String Manipulation
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  3  4  

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Wed 18 Apr 2012 12:44 AM (UTC)  quote  ]
Message
Actually, I had an epiphany. I think I'm just going to scrap that idea and recode it to work around the two choices each being an index in the table for each affliction. Like so:


herbcure  =  {

  addiction		=	{"ginseng", "ferrum"},
  agoraphobia		=	{"lobelia", "argentum"},
  asthma		=	{"kelp", "aurum"},
  blind			=	{"bayberry", "arsenic"},
  claustrophobia	=	{"lobelia", "argentum"},

}

And then I'll modify the CureHerb function to make it work.
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Tue 17 Apr 2012 01:12 AM (UTC)  quote  ]
Message
Sooo I have a brand new problem. I'm trying to integrate the new curing items from achaea into my curing system without completely rewriting it. First, here's the code:


herbaff		=	{

	"addiction",
	"agoraphobia",
	"asthma",
	"blind",
	"claustrophobia"

}

herbcure	=	{

	addiction		=	GinsengFerrumChoice() or "ginseng",
	agoraphobia		=	LobeliaArgentumChoice() or "lobelia",
	asthma			=	KelpAurumChoice() or "kelp",
	blind			=	BayberryArsenicChoice() or "bayberry",
	claustrophobia		=	LobeliaArgentumChoice() or "lobelia",

}

function GinsengFerrumChoice ()

	if outr.ginseng > 0 then

		return "ginseng"

	end

	if outr.ferrum > 0 then

		return "ferrum"

	end

	if inr.ginseng > 0 then

		return "ginseng"

	end

	if inr.ferrum > 0 then

		return "ferrum"

	end
	
end

function CureHerb ()

	for k, v in ipairs (herbaff) do

		if aff[v] then

			_G["herb"] = herbcure[v]

			if not (herb == "hawthorn") then

				if (tonumber(outr[herb]) > 0) then

					if EatGo() then

						HerbEat()
						Send ("eat " .. herbcure[v])

					return

					end

				elseif (tonumber(inr[herb]) > 0) then

					if OutrGo() then

						HerbOutr()
						Send ("outr " .. herbcure[v])

					return

					end

				end

			elseif balance.hawthorn then

				if (outr.hawthorn > 0) then

					if EatGo() then

						HerbEat()
						Send ("eat hawthorn")

					return

					end

				elseif (inr.hawthorn > 0) then

					if OutrGo() then

						HerbOutr()
						Send ("outr hawthorn")

					return

					end

				end

			return

			end

		end

	end

end



They pretty much made it so each affliction has two items that can cure it. My systems fine if I want to ONLY use the existing curing items, but i wanted to make it so that my curing system automatically uses the secondary item for each cure if I run out of the primary curing item. outr.<cure> refers to items that are in my inventory (and thus ready to be eaten) inr.<cure> refers to a cure that I have more of but are still in my rift.

In the case of the example function I showed, it would first check to see if I have ginseng in my inventory, then ferrum. If neither is in my inventory, it checks to see if either one is in my rift, checking ginseng first, then ferrum.
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Mon 16 Apr 2012 11:54 PM (UTC)  quote  ]
Message
Wow I can't believe I didn't catch that. Rookie mistake. Thanks Nick
[Go to top] top

Posted by Nick Gammon   Australia  (19,168 posts)  [Biography] bio   Forum Administrator
Date Mon 16 Apr 2012 07:26 AM (UTC)  quote  ]
Message

function ProvokeInventory()

	SendPkt("\255\250\201Char.Items.Inv\255\240")

end


That just defines a function. It doesn't execute it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Mon 16 Apr 2012 12:31 AM (UTC)  quote  ]
Message
Yea it didn't work..the aliases i'm making aren't provoking a response from the server. What's wrong with them?
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Sun 15 Apr 2012 08:51 PM (UTC)  quote  ]

Amended on Mon 16 Apr 2012 07:25 AM (UTC) by Nick Gammon

Message
Had a quick question about your SendGMCP function Twisol. Does it handle GMCP messages with empty string payloads, like Char.Items.Inv or number payloads like Char.Items.Contents 128976?

I was going to use such messages in an alias for INFO RIFT and INFO INV and was thinking I might be better off just putting the relevant Telnet codes and GMCP message directly into SendPkt, like so..



	<alias
		match="^INFOINV$"
		enabled="y"
		regexp="y"
		ignore_case="y"
		sequence="100"
		send_to="12"
		script="ProvokeInventory"
	/>

function ProvokeInventory()

	SendPkt("\255\250\201Char.Items.Inv\255\240")

end

	<alias
		match="^INFOCONT (\d+)$"
		enabled="y"
		regexp="y"
		ignore_case="y"
		sequence="100"
		send_to="12"
		script="ProvokeContainer"
	/>

function ProvokeContainer (name, output, wildcs)

	SendGMCP ("Char.Items.Contents ", wildcs[1])

end



I'll have checks in there once I get everything setup correctly to make sure that the number I use is actually in my inventory or in the room I'm in and make sure it's a valid argument. Number not a string, for example. But does that at least work?
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Fri 17 Feb 2012 09:09 PM (UTC)  quote  ]
Message
This is going to have to keep track of the room I was just in as well. unless IRE decides to add an entry in the exits object for the room ID of the room you end up in if you dash in that direction, or use non-standard movement like worm warp, wings, and the parthren gare. In the case of worm warp it would have to remove the room i'm in as the destination room of -that- room's worm warp exit too.

I'm wondering what kind of administrative distance value I'm going to assign for each type of movement. The value will be different depending on if that type of movement puts me at my destination or not. Worm warp has a few seconds of balance recovery, but if using it puts me in the destination room then it doesn't matter because there won't be any movement after that anyway.

I suppose if you have the dash ability, enough endurance, and a low enough ping it will always be faster than any other way of getting from one room to another on the same plane. I've already considered that certain routes might need a standard movement to "back up" a room or two back the way you came from a dash to put you into position to dash again. Unless the script that generates the route finds a faster way to get to that place that doesn't require taking that path.

Any other things I should consider for this endeavor?
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Fri 17 Feb 2012 06:33 PM (UTC)  quote  ]
Message
Twisol said:

You're using things like [exits] and [dash east], though, where I assume you meant ["exits"] and ["dash east"]. Careful there.


Yea something I need to be mindful of. Thanks for catching that!
[Go to top] top

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Fri 17 Feb 2012 04:03 AM (UTC)  quote  ]

Amended on Fri 17 Feb 2012 04:04 AM (UTC) by Twisol

Message
Kevnuke said:
EDIT: I just had an idea. Is this it?


for k, v in pairs (t.exits) do
  if not system.map[v] then
    system.map[v] = {}
  end
end

Yep, that's it. Good work!

[EDIT]: You're using things like [exits] and [dash east], though, where I assume you meant ["exits"] and ["dash east"]. Careful there.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Fri 17 Feb 2012 03:40 AM (UTC)  quote  ]

Amended on Fri 17 Feb 2012 03:47 AM (UTC) by Kevnuke

Message
Thanks for the help guys. That takes a load off of my mind. I should be okay with that now that I have a grasp on how to do that part. I believe I said before that I was going to make a table of all the rooms I come across in achaea using the room's ID number as the index and information about the room such as it's visible name and items in that room as a sub-table.


--see if this room is already in the map table and if not create an index for it containing an empty table
if not system.map[12346] then
  system.map[12346] = {}
end

system.map[12345] = {
  name         =  "Centre Crossing",
  description  =  "blah blah blah the center of Cyrene",
  exits        =  {
    n            =  system.map[12346],
    s            =  system.map[12347],
    e            =  system.map[12348],
    w            =  system.map[12349],
    in           =  system.map[12356],
    [dash east]  =  system.map[12389],
  },
  items  =  {
    system.items[874787],
    system.items[455729],
  }
}


I was going to make a for loop to check for the existence of an index in the system.map table for each room ID.

I'm a little confused as to the syntax to use on this though. Iterate through the named indices of the "exits" table resulting from using json.decode on the Room.Info message from GMCP.

like this..


t = json.decode("[" .. content .. "]")

-->

t[exits] = {
  n = 12346,
  s = 12347,
  e = 12348,
  w = 12349
}

Not sure how to make it check for each room in the exits table.

EDIT: I just had an idea. Is this it?


for k, v in pairs (t.exits) do
  if not system.map[v] then
    system.map[v] = {}
  end
end
[Go to top] top

Posted by Nick Gammon   Australia  (19,168 posts)  [Biography] bio   Forum Administrator
Date Tue 14 Feb 2012 12:44 AM (UTC)  quote  ]
Message
Kevnuke said:

Should I even worry about things like that when writing my scripts? Like how much clock time a script will use?


No, don't worry about that. Make it readable.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Mon 13 Feb 2012 08:32 AM (UTC)  quote  ]
Message
My mantra is to make it work first, then make it beautiful, and only after that should I make it fast. You might like to do the same. :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Mon 13 Feb 2012 07:18 AM (UTC)  quote  ]
Message
If there is a difference in speed it's probably negligible. You'd have to run the same thing through both functions a few million times to see the difference.

Should I even worry about things like that when writing my scripts? Like how much clock time a script will use?
[Go to top] top

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Mon 13 Feb 2012 01:16 AM (UTC)  quote  ]
Message
They might come out to the same thing in this particular case, but ipairs() better expresses that you're iterating over a list, rather than arbitrary key/value pairs.

I don't think either one is faster than the other. They're just for different things.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Kevnuke   USA  (86 posts)  [Biography] bio
Date Mon 13 Feb 2012 12:22 AM (UTC)  quote  ]
Message
I got the same result with pairs and ipairs. Is ipairs faster since it doesn't check non-numerical indices?
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


7,899 views.

This is page 1, subject is 4 pages long: 1 2  3  4  [Next page]

[New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]