call ds_list from diffrent object error - game-maker

I have created a textbox object and in its create event it creates list like
lines = ds_list_create();
in step event of textbox I use ds_list_add(lines, "line one");
and it works fine.
Now I have a diffrent object that try to call ds_list_add(Textbox.lines, "line from diff object");
but on running it gives error about var not set before reading. i tried also to change to global.list = ds_list_create(); and still same problems.
can someone explain how to call ds_list from diffrent object.

You can call ds_list_* functions right like you did. Just, you must make sure the data structures a function is referring to does actually exists.
I tried the following for testing purposes. Create two objects, objTextBox and objOther and set their events as follows.
For object objTextbox:
Create Event
list = ds_list_create();
Press 'Space' Event
var str = get_string("I'm objTextbox:","");
ds_list_add(list,str);
Draw Event
for (var i=0;i<ds_list_size(list);i++)
draw_text(10,10+15*i,string(ds_list_find_value(list,i)));
For object objOther:
Press 'Shift' Event:
var str = get_string("I'm objOther:","");
ds_list_add(objTextbox.list,str);
Now add them to a room, and make sure first object to be created is objTextbox, which is the one creating the ds_list. Run.
When dealing with data structures, always make sure they were created before working with them.

Related

Google Tag Manager - Parse Dynamic Data Layer Variable

I want to parse a 'pushed' data layer string. I intend to use it to track click events and setup the appropiate funnels in Google Analytics, it looks as follows: products.view.19|view recent product|19
The first part (products.view.19) is the unique page identifier.
The second part (view recent product) is the action.
The last part is (19) is the action identifier, this way actions may be grouped and compared more easily.
So I did the following, I first created a trigger (it fires when a link has the tag 'data-trackclick' in it) which pushes the data value to a variable (variable for datalayer). However, now I want to split that variable in to 3 new variables, as described above. I selected 'javascript macro' for this but somehow it returns 'undefined'. The macro looks as follows:
function() {
var data = {{TrackClickData}};
var pieces = data.split('|');
if (pieces[0].length()) {
return pieces[0];
} else {
return data;
}
}
Obviously this didnt work since it would only run on the initial load and not (like I thought) when the macro was requested, so it should somehow be fired on the 'click' and then set the variables accordingly.
Is this possible to do? Or do I really have to add the dataLayer.push() in script tags?
A few things:
.length() is wrong, the property for array length is .length without the ()
if it exists, pieces[0] is not an array, then .length would return the string length, see How do you check for an empty string in JavaScript? for more standard way of checking for empty strings
Is this possible to do? There's virtually nothing you can't do with GTM, since you can write JavaScript code, you can do whathever you code allows you to do, and splitting a string to use parts of it as variables is certainly within the realm of possibilities.
My advise is to make your code work outside GTM first (eg test it in the browser console), then once it's all working, port it to GTM.

moq returning dataReader

I'm having a strange experience with moq/mocking.
Im trying to mock the data going into a method so that i dont have to have adatabase available at test time.
So im loading in some data ive previously seralised.
Loading it into a dataTable, then creating a data reader from there, because my business layer method expects a data reader.
Then creating a mock for my data layer. and setting the return value for a particular method to my new datareader.
I am then setting (injecting) my mock data layer into my business layer so it can do the work of returning the data when the time comes..
var dataTable = DataSerialisation.GetDataTable("C:\\data.xml");
IDataReader reader = dataTable.CreateDataReader();
var mock = new Mock<IRetailerDal>();
mock.Setup(x => x.ReadRetailerDetails("00")).Returns(reader);
retailersBusinessLayer.RetailerDal = mock.Object;
var r = retailersBusinessLayer.GetRetailerDetail("00");
Now.. when the "GetRetailerDetail" is called is basically gets to "while(data.Read())" and crashes out but only sometimes.
I get the exception:
System.InvalidOperationException : DataTableReader is invalid for current DataTable 'Table1'.
Othertimes it move past that and can read some columns data, but other columns dont exist. (which must be to do with my serialisation method)
Well, this isnt exactly a satisfactory answer, but the code works now..
its similar to this.. in that no reason was found.
here
Anyway... as stated above the issue was ocuring inside my GetRetailerDetail method, where the code hits while(data.Read()) it throws the error..
The fix.. change the name of the data reader variable.. i.e. its was "data" and its now "data2".. thats all i changed.

How to bind background of a column in silverlight during runtime?

I have a grid with bunch of columns in it. To start with this grid is build during run time in the code behind and not much code in XAML except the generic grid, so I can't bind the column background during design time. I have been reading various blogs, questions and found the following as the closest answer.
SolidColorBrush backgroundBrush = new SolidColorBrush();
Binding b = new Binding("BackGroundColor");
b.Converter = new ColorConverterForReadOnly(); //This converter return color based on parameter
b.ConverterParameter = data;
BindingOperations.SetBinding(backgroundBrush, SolidColorBrush.ColorProperty, b);
column.Background = backgroundBrush;
When I ran the code, the binding did not happen, I put a break point (in the first line) inside the converter to see if debug hits the converter at all and it did not hit the converter at all. If I would put
column.Background = new SolidColorBrush(Colors.Blue)
I can see the the column colors set to blue.
What am I missing in the binding that is not letting converter invoked?
Thanks,
The binding is targeting a "BackGroundColor" property. For the binding to be hit, the DataContext of the column control would need to be an object that has a "BackGroundColor" property.

How to read xml tags and its data using flex?

I need to read xml tags and its datas from one file and then write it to another xml..how to do it?? please let me know immediately...?
See http://livedocs.adobe.com/flex/2/langref/XML.html . I find it hard to believe you googled this before asking.
You can use the FileReference.save() method to save XML data to a local file. It will prompt the user for a location to save the file first and then save the data.
Here's an example:
var xml:XML = <root><someXmlTag/></root>;
var fileReference:FileReference = new FileReference()
fileReference.save(xml, "myfile.xml");
As far as I knew, Flex wasn't able to write to files!
I use a HTTPService to load the XML file and a result even handler to access it.
<mx:HTTPService id="service" url="myXml.xml" result="ServiceResult (event)"/>
Do not specify a result format in the HTTPService tag.
This is the code for the result event handler.
private function ServiceResult (e : ResultEvent) : void {
e.result.XmlTag.AnotherXmlTag;
}
You can also use service.lastResult to access the last result returned by the HTTPService. The result is fully compatible with the dataProvider property, especially in arrays and chart series.
var series : LineSeries = new LineSeries ();
series.dataProvider = e.result.XmlTag.AnotherXmlTag;
This will take the value in all AnotherXmlTag tags within XmlTag. For series, though, you should also specify either a yField or and xField, but it digress :-)
If it doesn't work, you can also cast it using the as keyword, example:
series.dataProvider = e.result.XmlTag as ArrayCollection;
I haven't actually tried casting it in this scenario, but the bottom line is that XML tags are vary compatible with arrays and ArrayCollections.
In your case, you would just use e.result to get the complete XML file, assign it to a variable, and write it using Ben's method. You can also create an array from individual values using the way I explained above, and manually insert tags and such if you need. The advantage of this is that you have all the values ready in an array would you need them later on. If you loop through the indices, this won't require a lot of work, and it would be the way I'd do it.
Hope this helps!

Why is my ApplicationCache passing back a reference instead of a value?

This is an odd thing I've just run into.
I have a web application with a small DataTable stored in the ApplicationCache to reduce the amount of queries to a separate since the data is a lookup table that doesn't change often.
I access this DataTable twice within a given page. Once to bind the data to a drop down list in my Page_Load method:
dtDeptDivAct = GetAllDeptDivActCodes()
dtDeptDivAct.DefaultView.Sort = "LongDescription ASC"
ddlDeptDivAccount.DataSource = dtDeptDivAct.DefaultView
ddlDeptDivAccount.DataTextField = "LongDescription"
ddlDeptDivAccount.DataValueField = "Id"
ddlDeptDivAccount.DataBind()
...and once to retrieve additional data from the table when an index is selected in my ddlDeptDivAct_SelectedIndexChanged event:
Dim dtDeptDivAct As DeptDivActDataTable
If ddlDeptDivAccount.SelectedIndex > 0 Then
dtDeptDivAct = GetAllDeptDivActCodes()
dtDeptDivAct.DefaultView.RowFilter = "Id = " & ddlDeptDivAccount.SelectedValue
txtAddFundingDept.Text = DirectCast(dtDeptDivAct.DefaultView(0).Row, DeptDivActRow).Department.ToString.PadLeft(2, Char.Parse("0"))
txtAddFundingDiv.Text = DirectCast(dtDeptDivAct.DefaultView(0).Row, DeptDivActRow).Division.ToString.PadLeft(2, Char.Parse("0"))
txtAddFundingAct.Text = DirectCast(dtDeptDivAct.DefaultView(0).Row, DeptDivActRow).Activity.ToString.PadLeft(3, Char.Parse("0"))
Else
txtAddFundingDept.Text = ""
txtAddFundingDiv.Text = ""
txtAddFundingAct.Text = ""
End If
Note: The GetAllDeptDivActCodes() method is a simple method that returns the table from the ApplicationCache object.
The web page works fine. I can select my value and the proper values are insterted into the TextBox. However, when I go to a different page and come back to this page. My drop down list only has 1 value available for selection.
When I pulled up the debugger, I noticed that upon returning to the web page, when the GetAllDeptDivActCodes method returns the DataTable from the cache, the DefaultView RowFilter property was still applied to the DataTable, which was causing the problem.
I have fixed the issue for now by simply resetting the the DefaultView RowFilter once processing is done in the SelectedIndexChanged event, but why is the Application returning what appears to be a reference to the DataTable in the application cache when I was expecting a seperate copy (or value) of the object?
This is by design. Whenever you store an object in the Application State or Session State you are returned the actual object (or as you put it a reference to the object) when you access it. By design .NET objects are almost always passed by reference unless you specify otherwise. Forexample when passing objects to Functions they are passed by reference.

Resources