Field Collection alternative ? Need Sub fields searchable through Search API (Drupal 7) - drupal-7

I am hoping to find an alternative to Field Collection module. The problem is that I want to search (I am using Search API + Views) the sub fields in the Field Collection.
As an example, If I have a Field Collection "Field", as Research Paper, with following fields:-
Title of the Research
PDF Document.
I can add as many Research Papers in my Page where I added the Research Paper as the content type.
Following are, for example, the typical Research Papers I added:-
"Botany", "Finding a sustainable source of blah blah.pdf"
"Economics", "Research on correlation of customer spending and weather conditions.pdf"
"Mathematics", "Estimating Pi series within Rational numbers.pdf"
Now, comes the problem, if I made a Search Page through Search API by a view, and search "sustainable source of blah blah", how can I get the link to the 'Research Paper` entry of "Botany", "Finding a sustainable source of blah blah.pdf"?
I am using view and searching through "Fulltext search (exposed)".
Here is the view, just in case:
$view = new view;
$view->name = 'advanced_search';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'search_api_index_advanced_search_index';
$view->human_name = 'Advanced Search';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Advanced Search';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Search';
$handler->display->display_options['exposed_form']['options']['autosubmit'] = 0;
$handler->display->display_options['exposed_form']['options']['autosubmit_hide'] = 1;
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Indexed Node: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'search_api_index_advanced_search_index';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['title']['link_to_entity'] = 1;
/* Field: Indexed Node: The main body text » Summary */
$handler->display->display_options['fields']['body_summary']['id'] = 'body_summary';
$handler->display->display_options['fields']['body_summary']['table'] = 'search_api_index_advanced_search_index';
$handler->display->display_options['fields']['body_summary']['field'] = 'body_summary';
$handler->display->display_options['fields']['body_summary']['label'] = '';
$handler->display->display_options['fields']['body_summary']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['external'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['max_length'] = '200';
$handler->display->display_options['fields']['body_summary']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['body_summary']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['body_summary']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['trim'] = 1;
$handler->display->display_options['fields']['body_summary']['alter']['html'] = 0;
$handler->display->display_options['fields']['body_summary']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['body_summary']['element_default_classes'] = 1;
$handler->display->display_options['fields']['body_summary']['empty'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vitae est id metus vestibulum mattis. Donec sed dictum sapien. Proin facilisis vehicula elit nec molestie. Nullam scelerisque, urna non venenatis mattis, dolor neque ultricies tellus, quis lacinia mi ligula id risus. Curabitur congue gravida quam. Maecenas et luctus dui. Aliquam erat volutpat ...';
$handler->display->display_options['fields']['body_summary']['hide_empty'] = 0;
$handler->display->display_options['fields']['body_summary']['empty_zero'] = 1;
$handler->display->display_options['fields']['body_summary']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['body_summary']['link_to_entity'] = 0;
/* Field: Document Category » Uploaded File » The file.: Title Text (indexed) */
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['id'] = 'field_document_cat_field_field_document_file_field_file_image_title_text';
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['table'] = 'search_api_index_advanced_search_index';
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['field'] = 'field_document_cat_field_field_document_file_field_file_image_title_text';
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['field_api_classes'] = 0;
/* Filter criterion: Search: Fulltext search */
$handler->display->display_options['filters']['search_api_views_fulltext']['id'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['table'] = 'search_api_index_advanced_search_index';
$handler->display->display_options['filters']['search_api_views_fulltext']['field'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['group'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['exposed'] = TRUE;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator_id'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['label'] = 'Search me';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['use_operator'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['identifier'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['required'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['fields'] = array(
'title' => 'title',
'body:value' => 'body:value',
'field_document_cat_field:field_document:file:name' => 'field_document_cat_field:field_document:file:name',
'field_document_cat_field:field_document:file:field_file_image_title_text' => 'field_document_cat_field:field_document:file:field_file_image_title_text',
);
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'advanced-search';

You can try inline_entity_form or multifield modules.
related link : https://drupal.stackexchange.com/questions/81676/alternative-to-field-collection

Related

Unable to add more entries to Firebase after 11

I have a database in firebase that is meant to hold user data and I'm able to get it to add account data up to number 10 (zero based), but after that, anytime I call the function to add to the database it doesn't show up in Firebase. I am using this for a game in Unity. Here are the function calls.
`
public void populateDatabase()
{
//populate static account data
AccountData _thisAccount = new AccountData();
_thisAccount.accName = Account.instance.NickName();
_thisAccount.accEmail = PlayerAccount._this.getUserEmail();
_thisAccount.accCash = 100;
_thisAccount.accGem = 100;
//Ranking Values
_thisAccount.Rank = 0;
//rookie
_thisAccount.RookieRank = 0;
_thisAccount.RookieAverage = 0;
_thisAccount.RookieScoreOne = 0;
_thisAccount.RookieScoreTwo = 0;
_thisAccount.RookieScoreThree = 0;
//Amature
_thisAccount.AmatureRank = 0;
_thisAccount.AmatureAverage = 0;
_thisAccount.AmatureScoreOne = 0;
_thisAccount.AmatureScoreTwo = 0;
_thisAccount.AmatureScoreThree = 0;
//Semi
_thisAccount.SemiProRank = 0;
_thisAccount.SemiAverage = 0;
_thisAccount.SemiProScoreOne = 0;
_thisAccount.SemiProScoreTwo = 0;
_thisAccount.SemiProScoreThree = 0;
//Pro
_thisAccount.ProRank = 0;
_thisAccount.ProAverage = 0;
_thisAccount.ProScoreOne = 0;
_thisAccount.ProScoreTwo = 0;
_thisAccount.ProScoreThree = 0;
_thisAccount.accTricks = Account.instance.ReturnTricks();
string tName = _thisAccount.getAccName();
Debug.Log("Name: " + tName + " account " + _thisAccount.accTricks.Length);
Debug.Log("Email: " + _thisAccount.accEmail);
Debug.Log("Cash: " + _thisAccount.accCash);
Debug.Log("Attempt to fill Database info");
ConstuctDatabase(usersdb, _thisAccount);
}
private void ConstuctDatabase(DatabaseReference AccountRef, AccountData _thisAccount)
{
int num = 0;
AccountRef.RunTransaction(MutableData =>
{
num++;
List<object> account = MutableData.Value as List<object>;
if (account == null)
{
account = new List<object>();
}
else
{
Debug.Log("continue");
}
Dictionary<string, object> newAccount =
new Dictionary<string, object>();
newAccount["AccountName"] = _thisAccount.accName;
newAccount["AccountEmail"] = _thisAccount.accEmail;
newAccount["Cash"] = _thisAccount.accCash;
newAccount["Gem"] = _thisAccount.accGem;
//Ranking Values
newAccount["Rank"] = _thisAccount.Rank;
//rookie
newAccount["RookieRank"] = _thisAccount.RookieRank;
newAccount["RookieAverage"] = _thisAccount.RookieAverage;
newAccount["RookieScoreOne"] = _thisAccount.RookieScoreOne;
newAccount["RookieScoreTwo"] = _thisAccount.RookieScoreTwo;
newAccount["RookieScoreThree"] = _thisAccount.RookieScoreThree;
//Amature
newAccount["AmateurRank"] = _thisAccount.AmatureRank;
newAccount["AmateurAverage"] = _thisAccount.AmatureAverage;
newAccount["AmateurScoreOne"] = _thisAccount.AmatureScoreOne;
newAccount["AmateurScoreTwo"] = _thisAccount.AmatureScoreTwo;
newAccount["AmateurScoreThree"] = _thisAccount.AmatureScoreThree;
//Semi
newAccount["SemiProRank"] = _thisAccount.SemiProRank;
newAccount["SemiProAverage"] = _thisAccount.SemiAverage;
newAccount["SemiProScoreOne"] = _thisAccount.SemiProScoreOne;
newAccount["SemiProScoreTwo"] = _thisAccount.SemiProScoreTwo;
newAccount["SemiProScoreThree"] = _thisAccount.SemiProScoreThree;
//Pro
newAccount["ProRank"] = _thisAccount.ProRank;
newAccount["ProAverage"] = _thisAccount.ProAverage;
newAccount["ProScoreOne"] = _thisAccount.ProScoreOne;
newAccount["ProScoreTwo"] = _thisAccount.ProScoreTwo;
newAccount["ProScoreThree"] = _thisAccount.ProScoreThree;
//Trick Logic]
Dictionary<string, bool> newTricks =
new Dictionary<string, bool>();
int i = 0;
while (i < _thisAccount.accTricks.Length)
{
newTricks["Trick" + i] = _thisAccount.accTricks[i]._owned;
i++;
}
newAccount["TrickList"] = newTricks;
Debug.Log("ConstructDB1");
account.Add(newAccount);
MutableData.Value = account;
Debug.Log("ConstructDB2");
return TransactionResult.Success(MutableData);
});
}
`
Unfortunately, this is a known issue in 6.6.0. If you pay attention to the release page, I'd recommend upgrading as soon as possible.
Now an explanation of what's going on with a small workaround: an array is being serialized as effectively a dictionary with a numeric key. It's parsing numbers lexicographically (ex: it's doing some thing like 1, 10, 2, 3, 4, 5, 6...) and it breaks at 11. To work around this, rather than adding a list as you currently are, try serializing a dictionary with lexicographically ordered keys (ex: M001, M002, M003, &c). I know this isn't ideal, but it should unblock you for the time being!

C - realloc causes crash

I'm trying to implement a dynamyc array of strings (which can be any length) read from console. However it crashes on the realloc() call in the loop. The code:
void kill(char **memory, int count) {
if (memory != NULL) {
for (int i = 0; i < count; i++) {
if (memory[i] != NULL) {
free(memory[i]);
}
}
free(memory);
}
}
char **getData(int *strCount, int *allocatedCount) {
int maxStrCount = 10;
int maxStrLength = 10;
char **data = malloc(sizeof(char *) * maxStrCount);
if (data == NULL) {
return NULL;
}
for (int i = 0; i < maxStrCount; i++) {
data[i] = malloc(sizeof(char) * maxStrLength);
if (data[i] == NULL) {
kill(data, i);
return NULL;
}
}
int i = 0;
int j = 0;
for (char ch = getchar(); ch != EOF; ch = getchar()) {
if (ch == '\n') { // if end of line
data[i][j] = '\0';
i++;
j = 0;
if (i >= maxStrCount) {
// extend array
char **newData = realloc(data, sizeof(char *) * (maxStrCount * 2));
if (newData == NULL) {
kill(data, maxStrCount);
return NULL;
}
maxStrCount *= 2;
data = newData;
for (int k = i; k < maxStrCount; k++) {
data[k] = malloc(sizeof(char) * maxStrLength);
if (data[k] == NULL) {
kill(data, k);
return NULL;
}
}
}
} else { // if not end of line
data[i][j] = ch;
j++;
if (j >= maxStrLength - 1) { // extend string
maxStrLength *= 2;
char *newStr = realloc(data[i], sizeof(char) * maxStrLength); // Here it crashes
if (newStr == NULL) {
kill(data, maxStrCount);
return NULL;
}
data[i] = newStr;
}
}
}
if (j > 0) { // in case of file doesn't end with empty line
data[i][j] = '\0';
i++;
}
if (i == 0) { // in case of empty input
kill(data, maxStrCount);
return NULL;
}
*strCount = i;
*allocatedCount = maxStrCount;
return data;
}
The crash appears on the following input:
Lorem ipsum dolor sit
amet, consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
It happens like this: It reads "Lorem ips", then realloc is called, then reads "Lorem ipsum dolor s", then realloc is called again, all fine. Then it reads "amet, consectetur" (2-nd line) and "adipiscing elit, sed do eiusmod tempor " (3-rd line), then tries to realloc and crashes.
I watched all this trying to debug, but I still have no idea why does it crash.
You are sharing the variable maxStrLength between all strings.
You are reallocating the buffer for the 2-nd line and increasing that maxStrLength; however, when you are reading the next line, it's buffer is smaller, so you are writing into it out-of-bounds here:
data[i][j] = ch;

Flash CS3 Deleting objects on stage

Ok so I have this minigame inside my main timeline. The minigame creates a bunch of objects dynamically inside an array using addChild(new a0), new a1, new a2 etc... Anyways at the end of the game, there's an option to either restart (resets scores and goes back to starting frame) or finished (goes back a few frames to the "main screen" which is on a different layer and back a few frames. If I choose either options, any of the objects that werent deleted from playing the game (getting a match) are left on the stage even when restarting or going back to the main frame. I've tried various methods of calling removeChild, setting arrays to empty and what not and I can't seem to figure out how to remove them. With the code that I will display here, I get this error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at mousiesDay_fla::MainTimeline/clearGame()[mousiesDay_fla.MainTimeline::frame258:11]
at mousiesDay_fla::MainTimeline/tryAgain()[mousiesDay_fla.MainTimeline::frame258:29]
Here is the code
stop();
scoreWindow.visible = false;
scoreWindowText.visible = false;
finBtn.visible = false;
tryBtn.visible = false;
finBtn.removeEventListener(MouseEvent.CLICK, finished);
tryBtn.removeEventListener(MouseEvent.CLICK, tryAgain);
function clearGame() {
for( var i:int = 0; i < numClips; i++ ) {
removeChild( myClip[i] );
}
myClip.length = 0;
scoreWindow.visible = false;
scoreWindowText.visible = false;
finBtn.visible = false;
tryBtn.visible = false;
finBtn.removeEventListener(MouseEvent.CLICK, finished);
tryBtn.removeEventListener(MouseEvent.CLICK, tryAgain);
}
function finished(evt:MouseEvent) {
clearGame();
gotoAndPlay(256);
}
function tryAgain(evt:MouseEvent) {
clearGame();
gotoAndPlay(257);
}
backBtn.addEventListener(MouseEvent.CLICK, goBack);
function goBack(evt:MouseEvent) {
gotoAndPlay(256);
}
import flash.utils.*;
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener("timer", timedFunction);
myTimer.start();
function timedFunction(eventArgs:TimerEvent) {
var tc:int= 31 - myTimer.currentCount;
pTime.text = tc.toString();
if (myTimer.currentCount > 30) {
for (var k:Number = 0; k < numClips; k++) {
myClip[k].removeEventListener("mouseDown", pieceMove);
myClip[k].removeEventListener("mouseUp", pieceMove);
}
myTimer.reset();
myTimer.stop();
scoreWindow.visible = true;
scoreWindowText.visible = true;
addChild(scoreWindow);
addChild(scoreWindowText);
scoreWindowText.text = "Congratulations. You got " + upgameScore + " / 10. \nClick FINISHED to go back or TRY AGAIN to restart.";
finBtn.visible = true;
finBtn.addEventListener(MouseEvent.CLICK, finished);
addChild(finBtn);
tryBtn.visible = true;
tryBtn.addEventListener(MouseEvent.CLICK, tryAgain);
addChild(tryBtn);
}
}
var mySound:Sound = new correctSound();
upgameScore = 0;
var numClips:Number = 7;
var myClip = new Array(numClips);
myClip[0] = addChild(new a0());
myClip[1] = addChild(new a1());
myClip[2] = addChild(new a2());
myClip[3] = addChild(new a3());
myClip[4] = addChild(new a4());
myClip[5] = addChild(new a5());
myClip[6] = addChild(new a6());
//myClip[7] = addChild(new a7());
//myClip[8] = addChild(new a8());
//myClip[9] = addChild(new a9());
myClip[0].name = "piece0";
myClip[1].name = "piece1";
myClip[2].name = "piece2";
myClip[3].name = "piece3";
myClip[4].name = "piece4";
myClip[5].name = "piece5";
myClip[6].name = "piece6";
//myClip[7].name = "piece7";
//myClip[8].name = "piece8";
//myClip[9].name = "piece9";
var nph = new Array(numClips);
nph[0] = nph0_mc;
nph[1] = nph1_mc;
nph[2] = nph2_mc;
nph[3] = nph3_mc;
nph[4] = nph4_mc;
nph[5] = nph5_mc;
nph[6] = nph6_mc;
//nph[7] = nph7_mc;
//nph[8] = nph8_mc;
//nph[9] = nph9_mc;
var tpg = new Array(numClips);
tpg[0] = tpg0_mc;
tpg[1] = tpg1_mc;
tpg[2] = tpg2_mc;
tpg[3] = tpg3_mc;
tpg[4] = tpg4_mc;
tpg[5] = tpg5_mc;
tpg[6] = tpg6_mc;
//tpg[7] = tpg7_mc;
//tpg[8] = tpg8_mc;
//tpg[9] = tpg9_mc;
var x0 = myClip[0].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y0 = myClip[0].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
var x1 = myClip[1].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y1 = myClip[1].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
var x2 = myClip[2].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y2 = myClip[2].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
var x3 = myClip[3].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y3 = myClip[3].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
var x4 = myClip[4].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y4 = myClip[4].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
var x5 = myClip[5].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y5 = myClip[5].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
var x6 = myClip[6].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y6 = myClip[6].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
/*var x7 = myClip[7].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y7 = myClip[7].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
var x8 = myClip[8].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y8 = myClip[8].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
var x9 = myClip[9].x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
var y9 = myClip[9].y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;*/
var j:Number;
for (var k:Number = 0; k < numClips; k++) {
myClip[k].addEventListener("mouseDown", pieceMove);
myClip[k].addEventListener("mouseUp", pieceMove);
}
function pieceMove(evt:Event):void {
if (evt.type == "mouseDown") {
//mySound.play();
evt.target.startDrag();
}
else if (evt.type == "mouseUp") {
//mySound.play();
evt.target.stopDrag();
for (j = 0; j < numClips; j++) {
if (evt.target.name == "piece" + j &&
evt.target.hitTestObject(nph[j]) == true) {
removeChild(myClip[j]);
nph[j].alpha = 0;
tpg[j].alpha = 100;
if (j == 2) {
setChildIndex(tpg[j], 1);
}
upgameScore++;
}
else if (evt.target.name == "piece" + j) {
evt.target.x = Math.floor(Math.random()*(1+530-20))+20;//Math.random()*400+50;
evt.target.y = Math.floor(Math.random()*(1+380-20))+20;//Math.random()*50+50;
}
}
scor.text = upgameScore.toString();
if (upgameScore == 10) {
msgbox.text = "Congratulations !";
for (var k:Number = 0; k < numClips; k++) {
myClip[k].removeEventListener("mouseDown", pieceMove);
myClip[k].removeEventListener("mouseUp", pieceMove);
}
myTimer.reset();
myTimer.stop();
scoreWindow.visible = true;
scoreWindowText.visible = true;
addChild(scoreWindow);
addChild(scoreWindowText);
scoreWindowText.text = "Congratulations. You got " + upgameScore + " / 10. \nClick FINISHED to go back or TRY AGAIN to restart.";
}
}
}
I should mention that if you look near the end of the code where I do the testHitObject and then call removeChild after that, THAT particular delete works and removes the object from the frame.
Solved this one too. I should probably spend a bit more time before I post these.
As it turns out, when objects were being matched they were being removed as per the removeChild() function that was working. What I was doing then was iterating through the array and attempting to remove some objects that were already removed. So what i did was kept an array that matched the objects and when they were removed, changed a flag to 0. Then at the end, iterate through the new array and if there's a 1, remove the child object from the array with the same index. If there's a 0, ignore it. Now it works.

Creating array?

I have this class but i wanna make it 2D dimensional Array. And i do not know how to do it...Everyone tells me to create 2D array so i can easy call it and read array...but i found this way of making items.
Now array or gird that will store this times would be helpful.
Any code to transfer this class to an array would be helpful.
Weapon base is Inheriting 2 additional Classes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RPG
{
class WeaponList
{
private WeaponBase WoodenSword;
private WeaponBase RustySword;
private WeaponBase IronSword;
private WeaponBase SteelSword;
private WeaponBase BoardSword;
private WeaponBase MythrilSword;
private WeaponBase BloodSword;
private WeaponBase CoralSword;
private WeaponBase AncientSword;
public void CreateWeapon()
{
WoodenSword = new WeaponBase();
WoodenSword.ItemName = "Wooden Sword";
WoodenSword.ItemDescription = "A basic traning sword...can do some damage";
WoodenSword.IsStackable = true;
WoodenSword.Attack = 4;
WoodenSword.WeaponType = WeaponBase.WeaponTypes.Sword;
WoodenSword.ItemID = 1;
WoodenSword.Price = 10;
RustySword = new WeaponBase();
RustySword.ItemName = "Rysty Sword";
RustySword.ItemDescription = "Old rusty sword....still better than wooden one";
RustySword.Attack = 5;
RustySword.IsStackable = true;
RustySword.WeaponType = WeaponBase.WeaponTypes.Sword;
RustySword.ItemID = 2;
RustySword.Price = 50;
IronSword = new WeaponBase();
IronSword.ItemName = "Iron Sword";
IronSword.ItemDescription = "This sword has a broad and sturdy blade, but its iron construction makes it very heavy.";
IronSword.IsStackable = true;
IronSword.Attack = 6;
IronSword.WeaponType = WeaponBase.WeaponTypes.Sword;
IronSword.ItemID = 3;
IronSword.Price = 100;
SteelSword = new WeaponBase();
SteelSword.ItemName = "Steel Sword";
SteelSword.ItemDescription = "Hardend version of iron sword";
SteelSword.IsStackable = true;
SteelSword.Attack = 7;
SteelSword.WeaponType = WeaponBase.WeaponTypes.Sword;
SteelSword.ItemID = 4;
SteelSword.Price = 500;
BoardSword = new WeaponBase();
BoardSword.ItemName = "Borad Sword";
BoardSword.ItemDescription = "This broad-bladed sword is suited for large slashing strokes. It is inexpensive, but not particularly powerful. ";
BoardSword.IsStackable = true;
BoardSword.Attack = 8;
BoardSword.WeaponType = WeaponBase.WeaponTypes.Sword;
BoardSword.ItemID = 5;
BoardSword.Price = 800;
MythrilSword = new WeaponBase();
MythrilSword.ItemName = "Mythril Sword";
MythrilSword.ItemDescription = "A sword forged from the metal known as mythril. Its brilliantly shining blade is incredibly lightweight.";
MythrilSword.IsStackable = true;
MythrilSword.Attack = 10;
MythrilSword.WeaponType = WeaponBase.WeaponTypes.Sword;
MythrilSword.ItemID = 6;
MythrilSword.Price = 1600;
BloodSword = new WeaponBase();
BloodSword.ItemName = "Blood Sword";
BloodSword.ItemDescription = "The blade of this sword is a deep crimson, as if it were drenched in blood. It is cruelly sharp.";
BloodSword.IsStackable = true;
BloodSword.Attack = 8;
BloodSword.WeaponType = WeaponBase.WeaponTypes.Sword;
BloodSword.ItemID = 7;
BloodSword.Price = 1400;
BloodSword.specialAttack = "Drains Foe's HP";
CoralSword = new WeaponBase();
CoralSword.ItemName = "Coral Sword";
CoralSword.ItemDescription = "The handle of this single-edged sword has been decorated with intricate coral piecework.";
CoralSword.IsStackable = true;
CoralSword.Attack = 11;
CoralSword.WeaponType = WeaponBase.WeaponTypes.Sword;
CoralSword.ItemID = 8;
CoralSword.Price = 2200;
CoralSword.specialAttack = "Element: Thunder";
AncientSword = new WeaponBase();
AncientSword.ItemName = "Ancient Sword";
AncientSword.ItemDescription = "A sword constructed using ancient techniques that have long since perished from the world.";
AncientSword.IsStackable = true;
AncientSword.Attack = 11;
AncientSword.WeaponType = WeaponBase.WeaponTypes.Sword;
AncientSword.ItemID = 9;
AncientSword.Price = 3300;
}
}
}
Well I'm not sure what you're exactly doing, but making a 2D Array is quite simple:
int[,] MyArray = new int[3,4];
// Access like this:
MyArray[0,0] = 1;
MyArray[0,1] = 2;
MyArray[0,2] = 3;
// Etc...
// To Populate using a For Loop:
int i = 0;
for(int x=0; x < 3; x++)
for(int y=0; y < 4; y++)
{
i++;
MyArray[x, y] = i;
}
And that's how you make a 2D Array.
Edit:
Making it for a class is a similar process:
MyClass[,] MyArray = new MyClass[3,4];
// Access like this:
MyClass[0,0] = new MyClass();
MyClass[0,1] = new MyClass();
MyClass[0,2] = new MyClass();
// Etc...
// To Populate using a For Loop:
for(int x=0; x < 3; x++)
for(int y=0; y < 4; y++)
{
MyClass[x, y] = new MyClass();
}
As you can see making a 2D Array for a class is pretty much the same.
I suggest this way (vb-pseudo code).
Class WeaponBase
ItemName
ItemDescription
IsStackable
...
End Class
Class Weapons
inherits list (of WeaponBass)
Sub CreateWeapon
' here i will read data from XML or JSON instead of this below
w = new WeaponBase();
w.ItemName = "Wooden Sword";
w.ItemDescription = "A basic traning sword...can do some damage";
w.IsStackable = true;
add(w)
w = new WeaponBase();
w.ItemName = "Metal Sword";
w.ItemDescription = "A basic traning sword...can do some damage";
w.IsStackable = true;
add(w)
End Sub
Sub CreateNewItem(_name, _desc, _stackable)
w = new WeaponBase();
w.ItemName = _name;
w.ItemDescription = _desc;
w.IsStackable = _stackable;
add(w)
End Sub
End Class
and now you have a list of weapons that you can easily access and do whatevery you wish.

use linq method wcf ria

i have this method in my domainService
public IQueryable Getbl()
{
var qer = from t in this.ObjectContext.lignes_bl
from t0 in this.ObjectContext.entete_bl
where
t.NO_BL == t0.NO_BL
orderby
t.NO_BL,
t.NO_LIGNE
select new
{
IDentete_bl = t0.IDENTETE_BL,
NO_BL = t0.NO_BL,
DATE_BL = t0.DATE_BL,
FAC_AVOIR = t0.FAC_AVOIR,
REF_BL = t0.REF_BL,
CODE_CLIENT = t0.CODE_CLIENT,
NOM_CLIENT = t0.NOM_CLIENT,
ADRESSE = t0.ADRESSE,
CODE_PAYS = t0.CODE_PAYS,
VILLE = t0.VILLE,
CODE_POSTAL = t0.CODE_POSTAL,
ZONE = t0.ZONE,
TEL_FAX = t0.TEL_FAX,
CODE_ADL = t0.CODE_ADL,
NOM_ADL = t0.NOM_ADL,
ADRESSE_ADL = t0.ADRESSE_ADL,
CODE_POSTAL_ADL = t0.CODE_POSTAL_ADL,
VILLE_ADL = t0.VILLE_ADL,
MT_TTC_BL = t0.MT_TTC_BL,
CODE_PAYS_ADL = t0.CODE_PAYS_ADL,
TEL_FAX_ADL = t0.TEL_FAX_ADL,
REM = t0.REM,
CODE_REGLEMENT = t0.CODE_REGLEMENT,
NO_FACTURE = t0.NO_FACTURE,
DATE_FACTURE = t0.DATE_FACTURE,
CODE_COMPTA = t0.CODE_COMPTA,
SITE = t0.SITE,
CODE_COMMERCIAL = t0.CODE_COMMERCIAL,
NBR_COLIS = t0.NBR_COLIS,
NOM_TRANSPORTEUR = t0.NOM_TRANSPORTEUR,
FACTURE_DIRECTE = t0.FACTURE_DIRECTE,
MOIS_FACTURE = t0.MOIS_FACTURE,
CLE_SITE_MOIS_FAC = t0.CLE_SITE_MOIS_FAC,
CLE_SITE_FD_CC = t0.CLE_SITE_FD_CC,
CLE_SITE_FD = t0.CLE_SITE_FD,
CLE_SITE_FD_CC_EDIT = t0.CLE_SITE_FD_CC_EDIT,
ARCHIVAGE = t0.ARCHIVAGE,
NO_TVA_CL = t0.NO_TVA_CL,
numero = t0.numero,
Bis = t0.bis,
voie = t0.voie,
P_identite = t0.P_identite,
p_numero = t0.p_numero,
p_du = t0.p_du,
p_par = t0.p_par,
nais_du = t0.nais_du,
nais_ville = t0.nais_ville,
nais_dep = t0.nais_dep,
nais_pays = t0.nais_pays,
num_siren = t0.num_siren,
id_bon_ademe = t0.id_bon_ademe,
poids_ademe_vhu = t0.poids_ademe_vhu,
CODE_BROYEUR = t0.CODE_BROYEUR,
IDlignes_bl = t.IDLIGNES_BL,
CODE_CLIENT_LI = t.CODE_CLIENT,
NO_BL_LI = t.NO_BL,
DATE_BL_LI = t.DATE_BL,
FAC_AVOIR_LI = t.FAC_AVOIR,
CODE_ARTICLE = t.CODE_ARTICLE,
NO_VEHICULE = t.NO_VEHICULE,
DESIGNATION = t.DESIGNATION,
QTE = t.QTE,
PU_HT = t.PU_HT,
REM_LI = t.REM,
CODE_TVA = t.CODE_TVA,
TAUX_TVA = t.TAUX_TVA,
NO_LIGNE = t.NO_LIGNE,
TYPE_ARTICLE = t.TYPE_ARTICLE,
LIB_LIBRE = t.LIB_LIBRE,
DESI_ARTICLE = t.DESI_ARTICLE,
CODE_GARANTIE = t.CODE_GARANTIE,
NO_FACTURE_LI = t.NO_FACTURE,
CODE_REGLEMENT_LI = t.CODE_REGLEMENT,
SITE_LI = t.SITE,
LIB_MODELE = t.LIB_MODELE,
PA_HT_TTC = t.PA_HT_TTC,
PU_NET = t.PU_NET,
PU_TTC = t.PU_TTC,
code_id_article = t.code_id_article,
site_stockage = t.site_stockage,
sans_trait_haut = t.sans_trait_haut,
nom_article_unique_demonter = t.nom_article_unique_demonter,
code_ademe_ligne = t.code_ademe_ligne,
poids_ademe = t.poids_ademe,
type_article_ademe = t.type_article_ademe,
consistance = t.consistance,
conditionnement = t.conditionnement,
nombre_carcasse = t.nombre_carcasse,
num_vehicule_entretien = t.num_vehicule_entretien,
num_immat_vehi_entretien = t.num_immat_vehi_entretien
};
return qer.AsQueryable();
and i have this code in button ,the problem is does not contain a definition for Getbl ?
DomainService1 testContext = new DomainService1();
private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
InitializeComponent();
var res = testContext.Getbl();
}
Getbl returns an enumeration of an anonymous type. Anonymous types have only internal accessibility hence getbl is not included in service since that would in effect mean it would have return a list of type instances that should not be exposed publically.
Create a public class the has the list of Properties you want to return and include a new instance of this public class in your Select projection rather than using an anonymous type.
in addition to AnthonyWJones answer:
Use LoadOperation to get the data from the server:
LoadOperation<Customer> loadOp = this._customerContext.Load(this._customerContext.GetCustomersQuery());
CustomerGrid.ItemsSource = loadOp.Entities;
Note: Your method will have an appendix "Query" which RIA adds to Query methods.

Resources