0 Favourites

Problems with math

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

    <img src="http://lostrenegades.net/ET/timer.JPG" border="0" />

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

    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?

  • That math looks good to me - is there anything else changing the values? Could we see a simplified capx?

  • 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... <img src="smileys/smiley17.gif" border="0" align="middle" />

  • 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... <img src="smileys/smiley17.gif" border="0" align="middle" />

    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

  • 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))

  • 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))

    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

  • 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.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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

  • 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

  • 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?

  • Yeah random(a,b) gives you a random number in the [a;b[ range. For global variables, as soon as you nest them under an event or a group they become local variables and their scope is only in this event (and related sub-events) or group. Now, if you set your local variable as static, they will behave like global variables (meaning their value won't be reset at each tick) As far as boolean goes, inded you can't have boolean global variables. But you know, booleans are just 1 or 0 under the hood. If you really want to use TRUE and FALSE instead of number, you can still define them as constant of value 1 and 0.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)