if condition that checks if global is divisible by 5

Post » Sat Nov 17, 2012 8:14 am

So I'm tracking vampire kills in a global, setting up effects, abilities and powers that activate/become available at specific points.

One thing I wanted to do was everytime my counter hits a 5 kill increment, it cures the player of diseases, or possibly a 10 kill increment, either way, is there a way to have an if statement trigger if a variable is divisible by 5 or 10, if so, how would I express that?
Would I have to set up a function? Or is this just not really possible/there's a way easier way to go about this?

My global value is increased by a kill actor quest event right now.
if alias_killeralias.GetReference() == Game.GetPlayer()LoDKillCount.SetValueInt((LoDKillCount.GetValue() as int)+1)Debug.Notification(LoDKillCount.GetValueInt())endif stop()

^ Like this, I was thinking of having an extra if statement underneath that checks the global is the specified value for casting a cure disease spell, but I don't know if this is the best way to go about it.
User avatar
April D. F
 
Posts: 3346
Joined: Wed Mar 21, 2007 8:41 pm

Post » Sat Nov 17, 2012 8:52 am

Easiest way I can think of - probably not the most elegant ;) - is to stick the division (myGlobalValue / 5) in TWO temporary variables.

The first is an Int the second a float

Then ...

If MyTempInt == MyTempFloat
;... it divided by 5
else
;it did not
endIf

(at least I think that will work ... and not error ... in Pap ... Though hey, whadda I know, hmm? ;))



As to whether you are doing things the best way ... IDK, best ways are generally not my thing ... Someone whose thing they are, will no doubt be along shortly ...
User avatar
joseluis perez
 
Posts: 3507
Joined: Thu Nov 22, 2007 7:51 am

Post » Sat Nov 17, 2012 2:32 am

Wouldn't that just be comparing two answers that are the same? Or would a float calculate differently to an int? I'm confused. My brain no do so good with maths.

On sort of a similar note, at least it's relevant to using a global...will I be causing too much stress using a global variable to determine conditions for magiceffects firing in enchantments, both on hit and constant effect on player?
User avatar
I love YOu
 
Posts: 3505
Joined: Wed Aug 09, 2006 12:05 pm

Post » Sat Nov 17, 2012 4:05 am

Neither is mine :wink:

If the values were 12 and 5 then I THINK:

The Int value will be 2
The Float Value will be 2.4

Whereas, if the values were 10 and 5


The Int value will be 2
The Float Value will be 2


(Though, like I put earlier ... taking any notice of me is just as likely to involve you in 5 hours worth of useless work as it is to lead to the correct answer :wink:)




And as far as I know, GlobalVariables are quite "cheap" ... but like I said, best-ways-to-do-things aren't really my thing. Hopefully Justin, Amethyst, or one of the other code-gurus can help you there ...
User avatar
JD FROM HELL
 
Posts: 3473
Joined: Thu Aug 24, 2006 1:54 am

Post » Sat Nov 17, 2012 1:24 am

No prob, I'm leaning more in favour of just flat resistance rates to disease and then just granting a greater power that cures common disease. Seems like less hassle and it doesn't force the player to not be a vampire vampire hunter. See what I did there?

Edit: That and my...you know....intelligence...is stopping me from understanding all this glorious maths.

Edit: Also just stress tested the crap out of everything I've done so far, no performance impact on my machine, so everyone elses in the entire world simply HAS to handle it better.
User avatar
Katy Hogben
 
Posts: 3457
Joined: Mon Oct 30, 2006 12:20 am

Post » Sat Nov 17, 2012 11:37 am

Start with two ints, one at 0 and the other at 5. Increment the first with '+= 1' when the player kills a vampire and
Int iKilledVampires = 0Int iNextRevamp = 5If iKilledVampires == iNextRevamp	; Do Stuff	iNextRevamp += 5EndIf
User avatar
abi
 
Posts: 3405
Joined: Sat Nov 11, 2006 7:17 am

Post » Sat Nov 17, 2012 9:16 am

Thanks Justin, I actually understand that...somehow! Still torn on whether I'm going to implement it, but if I do decide to, that will come in mad handy!
User avatar
Laura Elizabeth
 
Posts: 3454
Joined: Wed Oct 11, 2006 7:34 pm

Post » Sat Nov 17, 2012 6:33 am

See ... I knew it involved ints :yuck:
User avatar
Dagan Wilkin
 
Posts: 3352
Joined: Fri Apr 27, 2007 4:20 am

Post » Fri Nov 16, 2012 11:14 pm

No prob :) Should work the same if using GlobalVariables, but you'd need to increment/check 'em differently
GlobalVariable Property iKilledVampireGLOB Auto ; 0GlobalVariable Property iNextRevampGLOB Auto ; 5If iKilledVampireGLOB.GetValue() == iNextRevampGLOB.GetValue()        ; Do Stuff        iNextRevampGLOB.SetValue(iNextRevampGLOB.GetValue() + 5)EndIf
User avatar
Shelby Huffman
 
Posts: 3454
Joined: Wed Aug 08, 2007 11:06 am

Post » Sat Nov 17, 2012 6:04 am

Can I actually bug you about something else, I noticed a condition for getrandompercent and also one for gethealthpercentage and decided to use them for an idea I wasn't sure how to implement originally.
So I have a "Constant Effect" heal for 100pts, that triggers when the player is at less than 5% Health and if getrandompercent returns a value lower than 10, to give a 10% chance of a nice big heal at a critical point, I'm calling it Salvation, anyway, besides the point, I wanted to attach a script to the magic effect that would pop up a message when it kicked in, just so the player knows why they're being healed randomly at a crucial point, credit where credit is due right?
So in my magiceffect I attached a script and used this to trigger the message:
Scriptname LoDSalvationScript extends activemagiceffectEvent OnEffectStart(Actor akTarget, Actor akCaster)LoDSalvation.Show()EndEventMessage Property LoDSalvation  Auto
Now naturally I'm doing something wrong, since my message never pops up. Everything else works better than I expected though, just the message. (Which I won't lie, was more or less copy-pasta from one of the divines shrines :P)
User avatar
Inol Wakhid
 
Posts: 3403
Joined: Wed Jun 27, 2007 5:47 am

Post » Sat Nov 17, 2012 2:29 am

To answer the original question in its simplest form "How do you check if something is divisible by 5", the answer is the modulus operator: %

If (MyVar % 5 == 0) ; Is divisible by 5, proceed    ; Code you want hereElse ; Is not divisible by 5

This is most useful if you want to alternate something using even/odd. Var % 2 only ever returns 0 or 1. If it's even it returns 0, and if it's odd it returns 1.

Now, in your case there is already a better solution. Just putting it out there for anyone else who reads the thread.
User avatar
herrade
 
Posts: 3469
Joined: Thu Apr 05, 2007 1:09 pm


Return to V - Skyrim