Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
8f2ff5eb
Commit
8f2ff5eb
authored
Feb 21, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated loops block code to retrieve type of loop variable.
parent
5aa375bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
blocks/loops.js
blocks/loops.js
+46
-0
No files found.
blocks/loops.js
View file @
8f2ff5eb
...
...
@@ -168,6 +168,52 @@ Blockly.Blocks['controls_for'] = {
option
.
callback
=
Blockly
.
ContextMenu
.
callbackFactory
(
this
,
xmlBlock
);
options
.
push
(
option
);
}
},
/**
* Finds the type of the variable selected in the drop down. Sets it to an
* an integer if it has not been defined before.
* @this Blockly.Block
* @param {Array<string>} existingVars List of variables already defined.
* @return {string} String to indicate the type if it has not been defined
* before.
*/
getVarType
:
function
(
existingVars
)
{
var
varName
=
this
.
getFieldValue
(
'
VAR
'
);
var
varType
=
null
;
// Check if variable has been defined already, add type if it has been.
for
(
var
name
in
existingVars
)
{
if
(
name
===
varName
)
{
varType
=
existingVars
[
varName
];
this
.
varType
=
varType
;
break
;
}
}
if
(
varType
==
null
)
{
// not defined, so set it to an int
varType
=
'
int
'
;
this
.
varType
=
'
int
'
;
this
.
setWarningText
(
null
);
}
else
if
((
varType
!=
'
int
'
)
&&
(
varType
!=
'
float
'
))
{
this
.
setWarningText
(
'
This variable type has been previously set to a
'
+
existingVars
[
varName
]
+
'
and it needs to be a number!
'
);
}
else
{
this
.
setWarningText
(
null
);
}
return
varType
;
},
/**
* Contains the type of the variable selected from the drop down.
*/
varType
:
'
nonono
'
,
/**
* Retrieves the type of the selected variable, defined at getVarType.
* @this Blockly.Block
*/
getType
:
function
(
existingVars
)
{
return
this
.
varType
;
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment