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
9eac6619
Commit
9eac6619
authored
Feb 22, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added static typing to the drop down variables in the math and text blocks.
parent
8f2ff5eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
7 deletions
+74
-7
blocks/math.js
blocks/math.js
+42
-3
blocks/text.js
blocks/text.js
+32
-4
No files found.
blocks/math.js
View file @
9eac6619
...
...
@@ -339,11 +339,50 @@ Blockly.Blocks['math_change'] = {
}
},
/**
* Assigns a type to the block, all these operations are floats.
* 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.
*/
getType
:
function
()
{
return
'
boolean
'
;
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
;
}
};
...
...
blocks/text.js
View file @
9eac6619
...
...
@@ -277,11 +277,39 @@ Blockly.Blocks['text_append'] = {
}
},
/**
* Assigns a type to the block, append always returns a string.
* @this Blockly.Blocks
* Finds the type of the variable selected in the drop down. Sets it to an
* a string 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
()
{
return
'
String
'
;
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
=
'
String
'
;
this
.
varType
=
'
String
'
;
this
.
setWarningText
(
null
);
}
else
if
(
varType
!=
'
String
'
)
{
this
.
setWarningText
(
'
This variable type has been previously set to a
'
+
existingVars
[
varName
]
+
'
and it needs to be a String!
'
);
}
else
{
this
.
setWarningText
(
null
);
}
return
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