virginharvester Posted September 29, 2018 Share Posted September 29, 2018 hi, sorry for my bad English and my bad math,I create some script to smelt ore to ingot,this is the example : while Game.GetPlayer().getItemCount(OreGold) >=2 Game.GetPlayer().removeItem(OreGold,2 , TRUE) Game.GetPlayer().addItem(IngotGold,1 , TRUE) endWhile it work, but it take to long,i like to use "integer div" but there no such thing in papyrus( i google it and found nothing),the script i like to create is simething like this : if Game.GetPlayer().getItemCount(OreGold) >=2 count = Game.GetPlayer().getItemCount(OreGold) div 2 Game.GetPlayer().removeItem(OreGold,2*count , TRUE) Game.GetPlayer().addItem(IngotGold,1*count , TRUE) endWhile can somebody help me , what that div formula in papyrus or there any other way to do that? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 29, 2018 Share Posted September 29, 2018 To divide in papyrus simply use / Example: count = (Game.GetPlayer().GetItemCount(Oregold) / 2)It is a good idea to get into the practice of wrapping your equations in () The reason being that when you get into more complex math you'll need them so that papyrus knows exactly which equations to do first. Link to comment Share on other sites More sharing options...
foamyesque Posted September 29, 2018 Share Posted September 29, 2018 Mod division is done through the % symbol. Ordinary division is /. Flooring to the nearest integer can be done via cast, e.g. x = (y / 2) as int. Link to comment Share on other sites More sharing options...
virginharvester Posted September 29, 2018 Author Share Posted September 29, 2018 To divide in papyrus simply use / Example: count = (Game.GetPlayer().GetItemCount(Oregold) / 2)It is a good idea to get into the practice of wrapping your equations in () The reason being that when you get into more complex math you'll need them so that papyrus knows exactly which equations to do first.thanks for tips, Mod division is done through the % symbol. Ordinary division is /. Flooring to the nearest integer can be done via cast, e.g. x = (y / 2) as int.thanks for info, but nearest integer, i there any true "div"? Link to comment Share on other sites More sharing options...
virginharvester Posted September 29, 2018 Author Share Posted September 29, 2018 (edited) anyway, i found a solution,this is the formula :c = a div b,c = (a - (a % b)) / b example :c = 9 div 2,c = (9 - (9 % 2)) / 2c = (9 - (1)) / 2c = ( 8 ) / 2c = 4 thanks for all replies. but if you have true div syntax, i will appeciate it Edited September 29, 2018 by virginharvester Link to comment Share on other sites More sharing options...
foamyesque Posted September 29, 2018 Share Posted September 29, 2018 (edited) For what you're trying to do, this: c = (9 / 2) as int Will make c = 4. Casting floats (e.g. 4.5) to integers is a truncation operation, and so will act as a floor operation as well. 4.1, or 4.8, will both cast to 4 as a result. Edited September 29, 2018 by foamyesque Link to comment Share on other sites More sharing options...
virginharvester Posted September 29, 2018 Author Share Posted September 29, 2018 ah For what you're trying to do, this: c = (9 / 2) as int Will make c = 4. Casting floats (e.g. 4.5) to integers is a truncation operation, and so will act as a floor operation as well. 4.1, or 4.8, will both cast to 4 as a result.ah thanks, but if the result is 4.9 it will count 4 right? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 29, 2018 Share Posted September 29, 2018 Floor "rounds" decimals down.Ceiling "rounds" decimals up. So using floor anything between 4.0 and 5.0 will become 4.While with ceiling they will become 5. Link to comment Share on other sites More sharing options...
foamyesque Posted September 29, 2018 Share Posted September 29, 2018 (edited) ah For what you're trying to do, this:c = (9 / 2) as intWill make c = 4. Casting floats (e.g. 4.5) to integers is a truncation operation, and so will act as a floor operation as well. 4.1, or 4.8, will both cast to 4 as a result.ah thanks, but if the result is 4.9 it will count 4 right? With a cast, any number between 4 and 5 will turn into 4. The Floor function Ishara linked will do the same thing, but casting is faster. The difference in behaviour with negative numbers (cast will truncate towards zero, floor will always go to the lowest integer) isn't relevant here. Edited September 29, 2018 by foamyesque Link to comment Share on other sites More sharing options...
virginharvester Posted September 29, 2018 Author Share Posted September 29, 2018 Floor "rounds" decimals down.Ceiling "rounds" decimals up. So using floor anything between 4.0 and 5.0 will become 4.While with ceiling they will become 5. ah For what you're trying to do, this:c = (9 / 2) as intWill make c = 4. Casting floats (e.g. 4.5) to integers is a truncation operation, and so will act as a floor operation as well. 4.1, or 4.8, will both cast to 4 as a result.ah thanks, but if the result is 4.9 it will count 4 right? With a cast, any number between 4 and 5 will turn into 4. The Floor function Ishara linked will do the same thing, but casting is faster. The difference in behaviour with negative numbers (cast will truncate towards zero, floor will always go to the lowest integer) isn't relevant here. owh, you talking about that thing, i not sure what is floor and ceiling, i thought you all talk about cell editing, , i not tested it yet, but thanks alot, that is new information for me Link to comment Share on other sites More sharing options...
Recommended Posts