Problems with math

Get help using Construct 2

Post » Wed Dec 19, 2012 9:38 am

Trying to teach myself and ran into some math issues, was wondering if anyone could point out what I did wrong.



The program as far as I have gotten it, (don't laugh I'm learning :P )

http://lostrenegades.net/ET/index.html

The buy values are supposed to be 110% higher than the sell values so that in any 60 second cycle a player cant just buy and sell an imbalanced item over and over for fast cash.

The sell values are randomly changed every 60 seconds by a rate of 80-120% of their former value.

When it starts out everything looks right, 10/11, 20/22, 30/33, but as time goes on you can see that while the values do randomly change, the ratios do not stay with buy price at 110% of the sell price.

If anyone can point out what I did wrong, I would appreciate it.

thanks,

narfi

ps. is there a tutorial on how to have objects placed dynamically to fit the screen instead of at a set coordinates from the upper left corner?

B
4
Posts: 7
Reputation: 339

Post » Wed Dec 19, 2012 11:26 am

That math looks good to me - is there anything else changing the values? Could we see a simplified capx?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Dec 19, 2012 3:41 pm

If the BuyValues is supposed to be 110% higher than the SellValues, shouldn't we see "Set MaterialBuyValue to int(Array.MaterialsSellValue*1.1)" ? The strange thing is that you got it right with ItemsBuyValue... Magistross2012-12-19 15:42:08
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Wed Dec 19, 2012 6:35 pm

[QUOTE=Magistross] If the BuyValues is supposed to be 110% higher than the SellValues, shouldn't we see "Set MaterialBuyValue to int(Array.MaterialsSellValue*1.1)" ? The strange thing is that you got it right with ItemsBuyValue... [/QUOTE]

Bingo!!!

Thanks, I knew it had to be something simple.
I just made the changes and going to run it a few minutes to test, but I am sure that's what it was.

My next steps in the learning process are to clean/tidy up what I've done so far. (separate background, main game, and HUD layers instead of all on one layer which is turning into a bit of a mess of having to do so much of the same thing over and over for each layout)

Then I want to learn how to work with the arrays better. I will want to break down the Materials, Ores, Items into multiple sub-types of each one as well as have differing base prices depending on which market they are in. (so 6 markets * 3types * 10 (sub-types each) * 2(buy/sell) = 360 variables or a 4 dimensional array?

I think though that since the player can only be in one market at a time I only need to store the base buy price and then have a new array for the 'local market' which gets its info from the big one and adds its own modifiers as needed.

Is this a good way to approach it, or is there a cleaner simpler method?

Also is there a visual way to view the array sort of like a spreadsheet? I am still having a little trouble getting a good mental picture of how It is working.

Thanks again,

narfi
B
4
Posts: 7
Reputation: 339

Post » Thu Dec 20, 2012 8:31 am

Hm, the thing is, you're not really using Arrays here. You just put some instance variable on the array and use these.
Every object can have instance variables. It's not really what arrays are for (:

Also, I think that your expression could be simplified this way:
newPrice = round(formerPrice * random(0.85,1.20))
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Dec 20, 2012 6:56 pm

[QUOTE=Yann] Hm, the thing is, you're not really using Arrays here. You just put some instance variable on the array and use these.
Every object can have instance variables. It's not really what arrays are for (:

Also, I think that your expression could be simplified this way:
newPrice = round(formerPrice * random(0.85,1.20))[/QUOTE]

Thanks, that is a much simpler expression. (I am assuming that random(0.8,1.2)will give me any range between those 2 numbers?)

And about arrays and variables, yes I am starting to see that now and not sure what is the best for what I want to do.

Dictionary sounds like a nice way to store info, and instance variables have been what I have been using, but what is best for storing a table of numbers?

I still don't really know how to use the array in a way that is easy for me to keep straight in my mind.

For example I want to store a table of base prices for things which vary by market. (for example 10 items and 6 markets.) And I would like to be able to easily get the value from for instance Item3 @ Market5.

In my mind i can visualize 2 and 3 dimensional arrays, but I think of them with labels for each row, column and depth. Is it possible to work with arrays that way, or can they only be used by number references?

Also what is the advantages and disadvantages to using Dictionary vs instance variables for storing variables?

Thanks for he help,

narfi
B
4
Posts: 7
Reputation: 339

Post » Thu Dec 20, 2012 10:02 pm

What you want is basically jagged arraylists (and possibly jagged arraylists of arraylists). Unfortunately, I don't think C2 can do that for now. BUT ! You can emulate them with the dictionnary and by using clever naming for your keys. Something like "Market1-Item3-SubCat2-SellValue" or "Market5-Material4-SubCat2-BuyValue" for examples.Magistross2012-12-20 22:04:05
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Thu Dec 20, 2012 10:10 pm

Yes it seems like dictionary may be the simplest thing for me to use at least during the learning stages.

What is the best way to pre-populate values in either the Dictionary or arrays?

With Dictionary I think maybe just have an event Dictionary is Empty and then enter everything that way. It should populate it all when the program first starts, and then unless I clear the dictionary it wont do it again, correct?

I suppose I could do something similar with an array as well.

thanks,

narfi
B
4
Posts: 7
Reputation: 339

Post » Thu Dec 20, 2012 11:33 pm

Just found out i can Right click in the events list and create global variables. This will be a lot simpler for a lot of the things I want to do. It gives me a 'visual' reference to look at as well which is nice.

narfi
B
4
Posts: 7
Reputation: 339

Post » Thu Dec 20, 2012 11:41 pm

Hmm for organization is there any way to put global variables in a group while still allowing the other groups access to them?

Part of what I am trying to learn now is organization and keeping things grouped so that I can focus on one thing at a time.

It may not be a problem though, it will be nice to have variables that are only within certain groups, but would be nice to have a collapsible group for the global ones shared by all the groups as well.

*edit* It also seems you cant set Global Variables as Boolian?narfi2012-12-20 23:46:10
B
4
Posts: 7
Reputation: 339

Next

Return to How do I....?

Who is online

Users browsing this forum: spacedoubt and 2 guests