Scripts / Help needed with shop script

Author
Message
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 5th May 2021 17:44
This is one of smallg's scripts which I have been trying to adapt to buy items rather than sell them to get a little trading system going in " A Tall Story" It seems to work for the first item but then doesn't add the second just adds the first. can anyone point out what I'm missing please.

Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 5th May 2021 18:05
The if at line '110' needs to be at the same level as the 'else' at line 150, this is why you should indent your scripts!
Been there, done that, got all the T-Shirts!
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 5th May 2021 18:29
Same level?
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 5th May 2021 21:39 Edited at: 5th May 2021 21:54
Same level of indentation if the script was indented properly.

i.e. the else should be matched with the if.



Actually that isn't the problem but this is now indented so it should be easier to figure out the problem.
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 6th May 2021 05:16
Alright, it's just that I almost never use those GetInKey() I think it's for simultaneous key presses.
It seemed to be duplicating the purchase, also there was no separation of item.

g_Scancode:
Q = 16
A = 30
Z = 44
Just count from there to the right. "O" = 24, "P" = 25, "[" = 26

Fixed it, do you want the fixed script, or is someone else working on it for you?
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 6th May 2021 14:39
Rename a second script, set this into your new @ context;
(BTW, we could add item name array if we wanted going forward)
add your sounds, images, etc, etc

-- Text(1,37,1,g_exotic_desert.." x "..item_name[12])
Text(1,40,1,g_RPG_Gold.." Gold")


if g_Scancode == 0 then pressed = 0 end -- no ghost keys

if g_Scancode == 26 and pressed == 0 then -- confirm purchase
pressed = 1

--check player has enough to purchase item
if g_RPG_Gold >= cost[item] then
g_RPG_Gold = g_RPG_Gold - cost[item]

if item == 1 then g_tuberscollected = g_tuberscollected + 1 end

if item == 2 then g_fiberscollected = g_fiberscollected + 1 end

end -- purchase if ENOUGH GOLD?
end -- pressed purchase key

--local keyp = GetInKey()

--cycle through items
if g_Scancode == 25 and pressed == 0 then
pressed = 1
if item < max_item then item = item + 1 else item = 1 end
end

if g_Scancode == 24 and pressed == 0 then
pressed = 1
if item > 1 then item = item - 1 else item = max_item end
end

-- debugger -- Text(22,22,3, "Select # "..item.." Want some "..item_name[item].." ?" )
end -- Player distance = close enough?



end -- main


.
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 6th May 2021 15:53 Edited at: 6th May 2021 17:47
@ GubbyBlips no just me working on it atm m8 (with any help i can get yeah if you have a working script it'd help speed things up for me ) I'm kinda working on a trading set in my project "A Tall Story" where basically the Merchant class can sail about to different lands and trade goods for exp and profit, 8 classes in total. Merchant, Hunter, Craftsman, Chef, Rogue, Fisherman, Sailor and Collector.
TBH any help is welcomed as the level creation takes forever and there are a lot of levels
Edit: just tested that code and it works fine thank you
edit2: stopped working and gave this error? weird the sell_price isn't a global?



Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on

Attachments

Login to view attachments
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 6th May 2021 18:52 Edited at: 6th May 2021 18:59
global doesn't matter really

**EDIT: if you want them to show up as GG GLOBALS, don't forget to add the g_ ahead of the variable;
g_sell_price = {}
but being a global or no is not the reason there's an error:

With variables, I like to compare them to introducing an associate to a friend.
They will not like company just popping in uninvited.
It's usually best, in fact with arrays you can't introduce (associate) a variable
to your friend the code runner until you have mentioned their type first.
before init place
sell_price = {}
**EDIT: change that to g_sell_price = {} AND all of them to g_sell_price = /amount/

And if any more similar errors appear, "mention" those variables first ahead
of the init before associating (introducing) them to the code runner.
Arrays ( like [6] ) will need = {}
Others like a straight, flat variable can be = 1, = 500, etc
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 7th May 2021 01:29 Edited at: 7th May 2021 01:43
sry m8 bit too confusing for me as I'm not really a scripter....want a map I'm your man so I've started to write what i think is a bit simpler. cos all these arrays and variables just confuse my old brain....so I have written this which works but the gold doesn't decrease. sry m8 but its like trying to teach your granny to eat gravel I can do a simple selling script for like 1 item which I may have to resort to but that's fine as it gives more traders on the map maybe I'm just getting above my head scripting wise. I can edit scripts but writing them from scratch i just draw a blank and when i get permanent errors i just look for a rope! maybe its old age lol


P.s the idea is to have multiple sellers e.g guys that sell food, goods etc etc so you can buy them in one area and the sell them in another at a profit....keeps the game rolling
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 7th May 2021 04:02
Yo, cool. I'm working on the script, and will get back to you next evening.
Are you interested in mouse control?
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 7th May 2021 14:35
Sure anything that works that i can edit for the other shops e.g trade goods, foods, lumber for ship building (have that script working ) I'm on map 3 of the first area which is where you trade, etc etc to earn enough for your ship, then the world opens up, next is the eastern isles.
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 7th May 2021 23:32
Sounds great stuff. "anything that works that i can edit for the other shops"
Well, not sure how that can be managed or your ideas. I guess how you was using the buying script?
I'm worried what I create might not be really easy to edit- or it might IDK?
But today things went south at home when I was messing with the cars check engine light that had been on a while, so I was occupied with that can of worms. (Lean fuel trim-- a slew of things can trigger it.) Then when I was about to drive a bit and live diagnose that-- I see a screw stuck in the tire! Glad I seen it before driving it, sad it's there at all! So I've got some busy tasks lined up.
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 9th May 2021 15:07
No worries m8 if and when you get time I'll keep working on it anyways
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 10th May 2021 01:57
Yeah, working on it a bit. At the moment I think it's a little illogical to just have a menu
that you click on - which adds items to your inventory, and no separate menu really for the shop.
IE -- one menu means your sack and the shop are the same menu... lol So gotta think on that one.
Also - I think we need some weight to the items in the inventory.
Exceed the weight limit, and you cannot buy more. And that should be something
that anyone could easily remove it they choose (or set to 28,000 metric tons).
PM

Login to post a reply

Server time is: 2024-04-26 09:58:02
Your offset time is: 2024-04-26 09:58:02