art3mis Posted July 29, 2018 Share Posted July 29, 2018 Can any VEXpression experts help me understand the following used in an Attribute Create node. Its from a .hip that demos light instancing. What exactly does the following return? /obj/light`int(fit01(rand($PT+1541)*2,1,2))` Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted July 29, 2018 Share Posted July 29, 2018 (edited) /obj/light`int(fit01(rand($PT+1541)*2,1,2))` Start reading it from the center of the brackets: (rand($PT+1541) // A random value between 0.0 and 1.0 is created based on the point number ($PT) + an additional seed value (1541) *2 // The random value gets multiplied 2, so now it´s between 0.0 and 2.0 fit01( XXX ,1,2)) // This get fitted from 0.0 - 1.0 to 1.0 - 2.0 (so multiplying it by 2 has not made much sense imho) int( XXX ) // The whole thing is casted to an integer, so in this case either 1 or 2 ` XXX ` // The back ticks probably turn this into a string, so you can combine it with: /obj/light So I guess it would switch between two light sources named light1 and light 2. Edited July 29, 2018 by konstantin magnus Quote Link to comment Share on other sites More sharing options...
Noobini Posted July 29, 2018 Share Posted July 29, 2018 (edited) methinks be careful with int() It's TRUNCATING....not just casting to type int. So just randomly....round(1.8) = 2 but int(1.8) = 1 To me the original method is a bit 'convoluted'.....where you'd need to digest this bit of info: fit01(num, newmin, newmax) Returns a number between newmin and newmax that is relative to num in the range between 0 and 1. If the value is outside the 0 to 1 it will be clamped to the new range. ...the 'outside' range bit... So I've fooled around with other methods...personally, I prefer the last....where you know it's one or the other..so simply add 1..assuming object names are obj1 and obj2... fit.hipnc Edited July 30, 2018 by Noobini Quote Link to comment Share on other sites More sharing options...
art3mis Posted July 30, 2018 Author Share Posted July 30, 2018 Thanks! Certainly seems convoluted if all we need to do is randomly switch between 1 & 2 ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.