New to scripting

Post Reply
casutton08
Posts: 4
Joined: Wed Sep 25, 2019 3:15 am

New to scripting

Post by casutton08 » Wed Sep 25, 2019 3:54 am

Well, I've been reading and reading, and trying to learn some steps, but I'm just not familiar enough with the syntax stuff to really figure out some of the things I need.

Here's what I've done so far:
-I'll send the command "Di Futures" to my game
-I Have a trigger set up to capture variables and send a command
Code: [show] | [select all] lua
^(.+) contracts in (.+) available at (.+)
send("c price " .. matches [3]])
and it does exactly what I want: the game says "Long contracts in fruit available at 525ig/ton." Client says c price fruit. brackets indicate my data collection I need
Long[2] contracts in fruit[3] available at 525[4]ig/ton.
+++ The exchange display shows the prices for Fruit +++
+++ Exchange will buy[5] 75 tons at 488[6]ig/ton +++

Here's the next step:
-I want to compare the output of c price [3] to some sort of logic. If [2] = Long and [5] = buy, or [2] = Short and [5] = sale then execute next step
-I want to set up a match formula where on true it creates a situation where the exchange price, divided by a number, is then subtracted from, or the [4] is subtracted from that number. ig:

Long contracts in fruit available at 525ig/ton.
+++ The exchange display shows the prices for Fruit +++
+++ Exchange will buy 75 tons at 488ig/ton +++

This contract is a long, and the exchange is buying. Therefore, (488/0.9) - 525 = a number I want displayed somehow. (Display [3] Spread = result)

The other thing about this, is that it's an array of results. When I type in "di futures" I get anywhere from 4 to 12 results, and the same number of "c price %var is entered:
Code: [show] | [select all] lua
>di futures

Laboratory Futures Exchange
Margin 4000ig/contract
  (Minimum 2000ig/contract)
Min movement 1ig/ton
Max hourly movement 5ig/ton
Short contracts in controllers available at 879ig/ton.
c price controllers
Long  contracts in fruit available at 522ig/ton.
c price fruit
Long  contracts in musiks available at 355ig/ton.
c price musiks
Long  contracts in nanos available at 412ig/ton.
c price nanos
Long  contracts in sensamps available at 624ig/ton.
c price sensamps
Long  contracts in soya available at 286ig/ton.
c price soya
Short contracts in tools available at 264ig/ton.
c price tools
Long  contracts in vidicasters available at 287ig/ton.
c price vidicasters
Short contracts in woods available at 871ig/ton.
c price woods
and the result of the commands is:
Code: [show] | [select all] lua
>c price controllers
+++ The exchange display shows the prices for Controllers +++
+++ Exchange will buy 75 tons at 825ig/ton +++
>c price fruit
+++ The exchange display shows the prices for Fruit +++
+++ Exchange will buy 75 tons at 513ig/ton +++
>c price musiks
+++ The exchange display shows the prices for Musiks +++
+++ Exchange has 19900 tons for sale +++
+++ Offer price is 380ig/ton for first 75 tons +++
>c price nanos
+++ The exchange display shows the prices for Nanos +++
+++ Exchange has 19864 tons for sale +++
+++ Offer price is 427ig/ton for first 75 tons +++
>c price sensamps
+++ The exchange display shows the prices for Sensamps +++
+++ Exchange has 3278 tons for sale +++
+++ Offer price is 655ig/ton for first 75 tons +++
+++ Exchange will buy 75 tons at 592ig/ton +++
>c price soya
+++ The exchange display shows the prices for Soya +++
+++ Exchange will buy 75 tons at 277ig/ton +++
>c price tools
+++ The exchange display shows the prices for Tools +++
+++ Exchange has 19900 tons for sale +++
+++ Offer price is 277ig/ton for first 75 tons +++
>c price vidicasters
+++ The exchange display shows the prices for Vidicasters +++
+++ Exchange has 19900 tons for sale +++
+++ Offer price is 304ig/ton for first 75 tons +++
>c price woods
+++ The exchange display shows the prices for Woods +++
+++ Exchange will buy 75 tons at 805ig/ton +++
I know this is a complicated one, but I'd like to figure this one out to automate this part of the game. As of right now, I'm copying/pasting into a spreadsheet, and despite trying to be accurate and complete, I keep mistyping values. If I can script this, and make it automated I can search more areas of this particular game. Any help is appreciated.

User avatar
demonnic
Posts: 576
Joined: Sat Dec 05, 2009 3:19 pm

Re: New to scripting

Post by demonnic » Wed Sep 25, 2019 5:02 pm

This is a very well written request for help. You may find it easier to work through something with this many steps on our discord server, where back and forth is a little easier. But if not I will try to answer your question as thoroughly as I can in a few hours when I'm done with work.

casutton08
Posts: 4
Joined: Wed Sep 25, 2019 3:15 am

Re: New to scripting

Post by casutton08 » Wed Sep 25, 2019 5:36 pm

I did join the discord server. I had the forms open and discord and thought... Eh this might be a forms question because there are a lot of steps involved. I will reach out on there when I'm home and behind the keys again. Thanks for reaching out! I'll post again once I have a solution just in case someone else needs it out there

casutton08
Posts: 4
Joined: Wed Sep 25, 2019 3:15 am

Re: New to scripting

Post by casutton08 » Fri Sep 27, 2019 5:29 am

I feel like I'm really close, now that I had some help from Discord. Just need a little help cleaning up syntax I think. The debug says "Lua syntax error:[string "Trigger: Futures"]:44: 'end' expected (to close 'for' at line 21) near ". As far as I can tell, I'm closing the for after my conditions are met. I'm heading to bed, so I figured I'd post it here to show my progress, and see if someone can help clean up that box a little bit. As far as I can tell, once this is done, I might just have the trigger I was looking for!

note: line 21 is where I have the first if function.
Code: [show] | [select all] lua
send("c price " .. multimatches [1][3])

Futures = {}

Futures = {
	commodity = multimatches[1][3],
	kind = multimatches[1][2],
	contract = multimatches[1][4],
	lprice = tonumber(multimatches[2][3]),
	sprice = tonumber(multimatches[4][2]),
	status1 = multimatches[2][2],
	status2 = multimatches[3][3]
	
	}

local WindowWidth, WindowHeight = getMainWindowSize();
createMiniConsole("Results",WindowWidth-650,0,650,300)
	
local goodcontracts = {}
	for kind, info in pairs(Futures) do
		if kind == "Long" and status1 == "buy" then do
			local margin = ((item.lprice/0.9)-contract)
		end
		if margin > 100 then
			goodcontracts[kind] = info
		end
	end
	for kind, info in pairs(Futures) do
		if kind == "Short" and status2 == "sale" then do
			local margin = (contract-(item.sprice/1.1))
		end
		if margin > 100 then
			goodcontracts[kind] = info
		end
	end		

cecho("Results", string.format([[
Futures Contracts:
%kind		%margin		/n
]], goodcontracts{}))

User avatar
Vadi
Posts: 4728
Joined: Sat Mar 14, 2009 3:13 pm

Re: New to scripting

Post by Vadi » Fri Sep 27, 2019 5:46 am

"then do" is not a thing, it is just "then". Might not solve all of the errors, but it is one of them.

casutton08
Posts: 4
Joined: Wed Sep 25, 2019 3:15 am

Re: New to scripting

Post by casutton08 » Fri Sep 27, 2019 2:36 pm

It fixed the syntax. Not quite working yet, but I feel like it's starting to come together.

User avatar
Vadi
Posts: 4728
Joined: Sat Mar 14, 2009 3:13 pm

Re: New to scripting

Post by Vadi » Fri Sep 27, 2019 3:06 pm

Excellent :D

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests