Get value in variable - game-maker

Hi, I'm pretty new to gamemaker and I'm trying to set a variable (global.b1) to the first value of "global.level_data". For example, global.b1 will be set to mimic the blue outline of "global.level_data"'s first value, which is 0. Can anyone tell me how to do this?

If I look at it correctly, you want to get the first value of an array
I think this should suffice:
global.level_data = [0,0]
global.b1 = global.level_data[0];
It may look confusing if you're not familiar with how arrays work, but the [0] represents the first value of the array (which happens to be 0 as well). The count of arrays also starts with 0 instead of 1.
For further understanding about arrays, I recommend reading this: https://manual.yoyogames.com/GameMaker_Language/GML_Overview/Arrays.htm
And as a side note: if you're creating new variables, the values in that variable will usually not update it's original form (e.g. changing the value global.b1 will not change the value in global.level_data[0] unless you set that yourself).
If you prefer the latter, then I think you're better off using global.level_data[0] for getting and setting directly

Related

Suppress/Filter a row

I am fairly new to using PeopleSoft BI Publisher plugin for MS Word and integrating it with PS Query Manager. My question is whether in the RTF file you can put logic to suppress or filter out data?
I have a for-each grouping that prints a line (row). I would like to add logic to NOT print the line if the Witholding amount field (M.WTHD_AMT) is equal to 0 (zero). My question is what would the syntax look like, and where should I place it (on the For Each grouping below, the Field level, or somewhere else?) I know I can alter the PS Query (data source) to do the filtering but I would like to leave that as-is and handle this in the template.
I see that there is another conditional IF statement ("rmt_") so I'm not sure if I can add this additional logic to that element or if I need a separate one. I appreciate any feedback!
EDIT:
I've added a new "Conditional Region" as suggested, and it works with just the WTHD_AMT criteria !0 to zero, however I tried added additional criteria where L.PYMNT_TYPE = 'R' and when I run the process it doesn't display data on the PDF output. Is there something wrong with the syntax? Do I need to have a separate Conditional Region for this 2nd criteria? I've seen another BI report where they have 2 or 3 criteria as part of one element.
<?if:number(M.WTHD_AMT)!=0.00?> and <?if:L.PYMNT_TYPE='R'?>
Option 1
You can nest <?if?> statements. Just add another <?end if?> at the end. Make sure there are no spaces between the all of the IF or END IF objects at the beginning or end of the content/row, else the row may still be displayed.
Option 2
You can add conditions in the repeating section. Below will repeat the region for every record where M.WTHD_AMT is not 0.00
<?for-each:record_path/record[M.WTHD_AMT!='0.00']?>
'Conditional Region' is the button you are looking for.
When using this button, make sure to double check where the if/endif or C/EC elements are added. It tends to ignore the selected element and join the elements to the start and end of the line. You will then need to cut and paste it into the right spot. For you this will probably be right after the F element and before the E element.

How to Add Column (script) transform that queries another column for content

I’m looking for a simple expression that puts a ‘1’ in column E if ‘SomeContent’ is contained in column D. I’m doing this in Azure ML Workbench through their Add Column (script) function. Here’s some examples they give.
row.ColumnA + row.ColumnB is the same as row["ColumnA"] + row["ColumnB"]
1 if row.ColumnA < 4 else 2
datetime.datetime.now()
float(row.ColumnA) / float(row.ColumnB - 1)
'Bad' if pd.isnull(row.ColumnA) else 'Good'
Any ideas on a 1 line script I could use for this? Thanks
Without really knowing what you want to look for in column 'D', I still think you can find all the information you need in the examples they give.
The script is being wrapped by a function that collects the value you calculate/provide and puts it in the new column. This assignment happens for each row individually. The value could be a static value, an arbitrary calculation, or it could be dependent on the values in the other columns for the specific row.
In the "Hint" section, you can see two different ways of obtaining the values from the other rows:
The current row is referenced using 'row' and then a column qualifier, for example row.colname or row['colname'].
In your case, you obtain the value for column 'D' either by row.D or row['D']
After that, all you need to do is come up with the specific logic for ensuring if 'SomeContent' is contained in column 'D' for that specific row. In your case, the '1 line script' would look something like this:
1 if [logic ensuring 'SomeContent' is contained in row.D] else 0
If you need help with the logic, you need to provide more specific examples.
You can read more in the Azure Machine Learning Documentation:
Sample of custom column transforms (Python)
Data Preparations Python extensions
Hope this helps

Constraints on BsplinesComp

I am using BsplinesComp for a sample problem.
The objective is to maximize the area under the line.
My problem arises when I want to set a constraint for one of the values in the output array that bspline gives. So a value such that the spline goes through that no matter what configuration it is in.
I tried this in two ways and I have uploaded the codes. They are both very badly coded so i think there is a neater way to do so. Links to codes:
https://gist.github.com/stackoverflow38/5eae1e86c5802a4df91becdf580d28c5
1- Using an extra explicit component in which the middle array value is imposed to be a selected value
2- Tried to use an execcomp but I get an error. Target shapes do not match.
I vaguely remember reading such a question but could not find it.
Overall I am trying to set a constraint for either the first, middle or last value of the bspline and some range that it should be in.
Similar to the plots here
So, I think you want to know the best way to do this, and the best way is to not use any extra components at all. You can directly constrain a single point in the output of the BsplinesComp by using the "indices" argument in the add_constraint call. Here, I constrain the first point in the spline to lie on the interval [-1, 1].
model.add_constraint('interp.h', lower=-1, upper=1, indices=[0])
Running the model gives me a shape that looks more like one of the ones you included.
Just for reference, for the errors you got with 1 and 2:
Not sure what is wrong here, but maybe the version you uploaded isn't the latest. You never used the AeraComp in a constraint, so it didn't do anything.
The exception was due to a size mismatch in connecting the vector output of the Bsplines comp to a scaler expression. You can do this by specifying the "src_indices", giving it a list of which indices in the array to connect to the target. model.connect('interp.h', 'execcomp.x', src_indices=[0])

Set value for multiple variables at once?

While programming a sample program in my TI-84 calculator, I was wondering if there were a way to initialize multiple variables to a single value in one line?
I tried doing
0 -> A,B,C,D
However this did not work for the calculator. I know you can do each one on an individual line, but my question is, is it possible to initialize multiple variables to a single value at once in TI-BASIC?
No. You cannot initialize multiple variables to a single value at once in TI-Basic.
However, you can:
Set all values in an array or matrix to the same value at once.
Initialize variables to zero in three bytes instead of four using DelVar (variable) and then leaving off the following colon. For example, instead of doing :0->A:0->B:Disp A,B you can do :DelVar ADelVar BDisp A,B.
Remember that uninitialized variables are treated as zero when first used.
No, you can't set multiple variables at once with one value. But if you just want them on the same line, you can use a colon like this 0→A:0→B. If you really feel like it, you could make another program that zeroes out every variable and just call it from within your program like this.
PROGRAM:ZERO
:0→A
:0→B
:0→C
...
PROGRAM:OTHER
:prgmZERO
...

Strange QTableWidget behavior - not all cells populated after sorting followed by repopulating

I have a QTableWidget that I populate like this:
// Clear the table
this->topPatchesTableWidget->setRowCount(0);
this->topPatchesTableWidget->setRowCount(numberToDisplay);
for(unsigned int pairId = 0; pairId < numberToDisplay; ++pairId)
{
// Display patch match scores
QTableWidgetItem* myLabel = new QTableWidgetItem;
myLabel->setData(Qt::DisplayRole, myValues[pairId]);
this->tableWidget->setItem(pairId, 0, myLabel);
... fill other columns ...
}
(I have some other UI elements to set properties that compute the values in myValues). If I change the properties, recompute, and recreate the table, everything works as expected. If I sort the table by clicking on one of the headers, it sorts correctly. HOWEVER, if at this point (after sorting) I click my button again to recompute the values and recreate the table, the table is very broken. That is, many of the cells are empty, and the cells that are not empty don't seem to be in any particular order.
By adding a manual call to
this->tableWidget->sortByColumn(0, Qt::AscendingOrder);
at the beginning of my CreateTable function, everything works as expected, but of course the newly created table is sorted by column 0 rather than the column that was selected for the last sort.
Does anyone have any idea why things would go so wrong without the call to sortByColumn? (I tried to make a simple example but I can't replicate the problem in a demo program).
Thanks,
David
I had a similar problem in python, if a column header was selected to enable sorting the cells after that column stopped populating.
I got around it by setting self.tableWidget.setSortingEnabled(False) at the beginning of the row add method, then setting it back to self.tableWidget.setSortingEnabled(True) at the end of the row add method. According to riverbank computing this is the officially recommended way to address this problem.
QTableWidget.setItem (self, int row, int column, QTableWidgetItem item)
Note that if sorting is enabled (see sortingEnabled) and column is the current sort column, the row will be moved to the sorted position determined by item.
If you want to set several items of a particular row (say, by calling setItem() in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. setItem() will not move the row).
See also item() and takeItem().
This is an elaboration on Karnisov's answer, also with PyQt. Disabling sorting before doing any setItem()s also worked for me, but it caused the user's sort selection to be lost, so I did it like this, where t is a QTableWidget:
oldSort = t.horizontalHeader().sortIndicatorSection()
oldOrder = t.horizontalHeader().sortIndicatorOrder()
t.setSortingEnabled(False)
# make the changes
t.sortItems(oldSort, oldOrder)
t.setSortingEnabled(True)
Note that it is still possible for the sort to change slightly with this code. This appears to be because the sort that Qt is using here doesn't move any items that were already in order, so if we had a table like this:
NUMBER LETTER OTHER LETTER
1 B C
2 G Q
3 A Q
If we sort by NUMBER, then by OTHER LETTER, nothing changes. But if we sort by LETTER, then by OTHER LETTER, we get:
NUMBER LETTER OTHER LETTER
1 B C
3 A Q
2 G Q
So if we had previously sorted by LETTER, then OTHER LETTER, this code would only do a single sort by OTHER LETTER, and we'd end up with the second version of the table instead of the first (assuming that the order the elements were added to the table in matches NUMBER). In this spot in my code, all items are deleted and re-added to refresh the table, so this can sometimes cause noticeable changes in order.
I had the same problem - always, when I wanted to insert new data, i buildet the header and setSortingEnabled(true). I guess the QTableWidget does not like several calls for setSortingEnabled(true). So I put it into the constructor of my MainWindown, and thats it!
I never figured out what was wrong with this. I gave up and implemented a custom model/view which is probably a much better idea anyway.

Resources