There isn't a function to set the value of a field. You can generally set the value of a field with the following code.
$entity->$fieldname[$language][$delta] = $value;
What changes for every field is the array you pass in $value
. For example, the body field of a node uses the following structure.
array(
'value' => 'Empty text. Revision 3.',
'summary' => '',
'format' => 'full_html',
'safe_value' => '<p>Empty text. Revision 3.</p>',
'safe_summary' => '',
);
The structure used for a taxonomy term is the following one.
array(
'tid' => 4,
);
$delta
is a value that is normally 0, but for fields with multiple values it can have any value, as long as it is not higher than the maximum number of values it can get (which can be set in the user interface for a specific field).
$language
is the language ID, and it can also be set to LANGUAGE_NONE
.