Jump to content

[LE] about math : div and mod in papyrus


Recommended Posts

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

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

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

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?

 

 

 

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 by foamyesque
Link to comment
Share on other sites

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

 

 

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...