CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ruby & Ruby On Rails (http://www.codingforums.com/forumdisplay.php?f=44)
-   -   Resolved Loopy problem - variable ignoring block (http://www.codingforums.com/showthread.php?t=216370)

chrisglasier 01-26-2011 08:22 AM

Loopy problem - variable ignoring block
 
Code:

def Skel_poser.run_frames(time,lframe)       
                keyframes = {}
                model = Sketchup.active_model
                d = model.attribute_dictionaries['kframes']
                d.each_pair do | key,value |
                        a =  1
                        value.each do| v |
                                if v.nil?
                                        v = [[1,0,0],0]
                                end
                                v << time * a
                                a += 1
                        end
                        keyframes[key] = value
                end
                return keyframes
        end

This code runs fine if there are no empty elements in the value array. If there are puts v shows the change from nil to the new array but value shows the original nil.

What have I done wrongly ... please!

chrisglasier 01-27-2011 03:25 AM

Solved
 
Code:

def Skel_poser.run_frames(time,lframe)       
                keyframes = {}
                model = Sketchup.active_model
                d = model.attribute_dictionaries['kframes']
                d.each_pair do | key,value |
                        a =  1
                        new_value = []
                        value.each do| v |
                                if !v
                                        v = [[1,0,0],0]
                                end
                                v << time * a
                                a += 1
                                new_value << v
                        end
                        keyframes[key] = new_value
                end
                #p keyframes
                return keyframes
        end



All times are GMT +1. The time now is 05:15 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.