How to Loop a script in gamemaker - loops

cantSee = collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true)
canSee = !(collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true))
Define the loop as the following:
if cantSee {
cantSeeTimer = cantSeeTimer +1
}
if cantSeeTimer >60 {
speed=0
stopped=true
} else {
mp_potential_step(obj_player.x,obj_player.y,5,false)
}
}
if stopped=true && canSee {
mp_potential_step(obj_player.x,obj_player.y,5,false)
loop()
}
I know the language is bad, but I just want to create a loop command to summon at will.
Thanks, Finn.

so you haven't specified which object in your game currently has this code but it shouldn't matter too much.
So in Game Maker or Game Maker Studio there are a series of events an object can have and one of them is called a "Step" event. A step event is basically a loop that will cycle the amount of times the room speed is per second. Eg: If the room speed of a room is 30 the step event will loop 30 times per second.
I think I can see what you are trying to do and I think I have a solution for you.
Since you can write GML code I am going to assume you understand how to use the GMS or GM IDE.
We want to create a new object called obj_control (or you can choose a custom name). Also don't give this object a sprite as we don't want the player to see it.
Now we want to add an event to our new object so make sure you still have the windows for obj_control (or whatever u called it open). and click on the 'Add Event button' shown in this image: http://imgur.com/A7szwFO
Once you click on it, click on 'Step'. http://imgur.com/s0ksiyD
Now select 'Step' again. ('Begin Step' and 'End Step' don't do what we want so let's just ignore them)
Now we need to add your code to the step event we just created. So make sure you are on the 'Control' tab and find the script editor (you should know where to find it) and drag one into the 'Actions' for the step event.
http://imgur.com/de3gE01
Now a script editor should pop up automatically but if it doesn't just double click the "Execute piece of code". Now we just need to copy and paste all of your code into the script editor.
http://imgur.com/sNBOCFu
Now click on the green tick on the top left corner of the window to save the code.
Now before we are done let's make sure we define the variables in a create event. So make a create event and add this code:
cantSee = collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true)
canSee = !(collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true))
After you have added that create event and inserted that code into it save all changes to the object.
All that is left is to add this object we created to every room of the game so it can function.
Hopefully this helped and if it didn't just let me know and we can get it sorted.

Related

Trigger/run earlier interaction in Selenium WebDriver

I want to achieve the following process. The scripts are written in Katalon, but it does not matter. Selenium approach is enough.
I test an appearance of two elements in a dialog window. If a text message appears, the second element will not come and the dialog window is closed. If the first element (message) is not displayed, a button that displays after a certain amount of time is clicked.
I would like to continue and avoid using wait until element is visible/invisible. I do not know how to do it, but any action is triggered first it will go through it.
The problem is that the test waits for the message for the certain time and if it not displayed in (let say 30 sec), it clicks on the button. I want to avoid to wait until it is visible, and instead of waiting just to click immediately on the button. So the aim is to track two parallel actions (not selenium actions) and which one is fired first. Is there any approach? Maybe using tasks?
Here is the code:
TestObject dialogWinEl = findTestObject("Object Repository/FinacDocAndPayments/dialogWindow/div_dialogWin")
WebUI.waitForElementVisible(dialogWinEl, GlobalVariable.TIMEOUT_ELEMENT, FailureHandling.OPTIONAL)
TestObject statusMsgFilesDownloadEl = findTestObject("Object Repository/InvoiceDetailPage/div_dialogWin/span_noDocFoundStatus")
boolean noDownloadFiles = WebUI.waitForElementVisible(statusMsgFilesDownloadEl, GlobalVariable.DOWNLOAD_BTN, FailureHandling.OPTIONAL)
if(noDownloadFiles){
KeywordUtil.markPassed("No files found to download. Closing dialog")
}
else{
KeywordUtil.markPassed("Files found. Click on Download files")
TestObject btnEl = findTestObject('Object Repository/InvoicesAndPayments_Global/btn_generic', [('btn_text'):btnName])
WebUI.waitForElementClickable(btnEl, GlobalVariable.TIMEOUT_ELEMENT)
WebUI.click(btnEl)
KeywordUtil.markPassed("File downloaded. Closing dialog window")
}
TestObject xBtn = findTestObject('Object Repository/InvoicesAndPayments_Global/confDialog/div_closeBtn')
WebUI.waitForElementClickable(xBtn, GlobalVariable.TIMEOUT_ELEMENT)
WebUI.click(xBtn)
KeywordUtil.markPassed("Dialog window has been closed")
Basically the variable noDownloadFiles is equal to the status of the particular element (visible or not) and it waits for the time that is in the var GlobalVariable.DOWNLOAD_BTN = 20sec. The problem here is if this variable is false it means that it waited for the specific amount of time and then it continues in the else branch. The point is if the button appears earlier it does not have to wait to see if statusMsgFilesDownloadEl is visible or not.
I simply want to use this:
WebUI.waitForElementVisible(statusMsgFilesDownloadEl, GlobalVariable.DOWNLOAD_BTN, FailureHandling.OPTIONAL)
and
WebUI.waitForElementClickable(btnEl, GlobalVariable.TIMEOUT_ELEMENT)
and once the first or second is evaluated it continues. There is no reason to wait for one and then for the other.

Movie Clip Object adding Multiple Times with Enter_Frame Event

Hey Guys so I am using TweenLite to act as a timer for Performance with Mobile usage. I ran into a little problem here that I can't seem to figure out. So In my ENTER_FRAME Listener I have this function difficultyController Where I add my TweenLite control like so:
private function difficultyController():void
{
if (nScore >= 10)
{
TweenLite.delayedCall(nChainsaw, addChainsaw);
trace("DIFFICULTY_UPDATE");
}
}
In my addChainsaw Function I have the Movie Clip Objects added to the stage like so:
private function addChainsaw():void
{
TweenLite.delayedCall(nChainsaw, addChainsaw);
var newChainsaw = new mcChainsaw();
//Add Child
addChild(newChainsaw);
//Push Move CLips into array
aChainsawArray.push(newChainsaw);
trace(aChainsawArray.length + "chainsaw");
}
Now I want the chainsaw Movie clip in the array to be added to the stage every 2 seconds which is what the value of nChainsaw is. Ill kill it off when the nScore reaches a higher number. But as of right now when I test the Game like so It adds Multiple Movie clips over and over again then freezes the game. I know it has to do with the ENTER_FRAME Listener But I don't know what else to do. SHould I just remove the TweenLite and add A Actual Timer and in the diffucultyController(); just add timer.start??
If anyone has anyother Ideas I would really Appreciate it thanks!

How to add next and previous buttons in matlab?

We create a matlab gui for registration.In that form we have to see each images from an array on the buttons clicks. we need to be implement two pushbuttons ie 'next' and 'previous'. when we click previous we have to see previous image on the axis and vice versa. plz help us. Thank you in advance.
Well, the steps are pretty straightforward:
In your GUI's OpeningFcn you should add code to load the images from the folder:
create a cell array filed in handles, e.g. handles.img_store;
load images one by one in handles.img_store{:} using imread();
create a current image index, e.g. handles.img_index, and initialize it to 1;
display the current image using display_current_image() function—see 4.;
Write the callback for the pushbutton "Next" to increment handles.img_index, reset it to previous value if it goes out of bounds of handles.img_store, then call display_current_image()—see 4.;
Write the callback for the pushbutton "Previous" to decrement handles.img_index, reset it to previous value if it goes out of bounds of handles.img_store, then call display_current_image() function—see 4.;
Create a function, e.g. display_current_image() that will take handles as argument and, using the image() function, displays the image with the index handles.img_index in the cell array handles.img_store
I will not write code, not until you try to write some code first. :-)

LimeJS animation.Sequence does not complete

i have got a probling concerning my animation.Sqeuence.
Only the first Sequence Element is being executed. The 2nd is ignored.
I want the Sprite spell_1 to move to the Hero (hero_x_exact,hero_y_exact), and after that to the destination.
Each element works fine for itself but not in a Sequence.
goog.require('lime.animation.Sequence');
...
var spellmovement = new lime.animation.Sequence(
spell_1.runAction(new lime.animation.MoveTo(hero_x_exact,hero_y_exact).setDuration(1).enableOptimizations()),
spell_1.runAction(new lime.animation.MoveTo(target_coord_x_spell,target_coord_y_spell).setDuration(1).enableOptimizations())
);
What might work better is using a spritesheet with each animation on the spritesheet Then you can build something that loads each animation by name. Obj_Walk001.png, Obj_Walk002.png
Then create a method to read each animation per frame in the scheduling manager.
You can find an example of this code in limejs/lime/demos/test. Then goto run.htm and click on Frame4 this one will show you how limejs is going it.

Show progress bar when sending pages to the printer (WPF)

I am creating printouts in WPF using flow documents. These printouts are set in separate window where DocumentViewer is placed.
When user clicks print I would like to show a progress bar that informs about current page that is sending to the printer. How can I do this?
I'm not sure exactly where your print code is, or where you want the progress bar, but I did something similar to this recently. This will be in VB.net.
First of all, create a new progressbar in the same class as the code you use to send the page to the printer. Then, we're going to take advantage of the "top-down" order in a block of code to change the progress bar.
The progress bar's value should be set to "0" be default. Now, in the code for sending the page to the printer, you're going to increase the progressbar's value (such as with the code "MyProgressBar.Value = MyProgressBar.Value + 1"). Put this code in between each line of the code you want to show progress for.
I would change the "+ 1" part of the code, however, to another value, so your progress bar progresses equally after each step. If you have three lines of code, then use "+ 33" (100\3), four lines use "+ 25", etc.
Finally, at the end of the code, set "MyProgressBar.Value = 100"
This only works, however, if you have access to a code longer than one line. For one line of code, I'm not sure how this works, unless you can get to the block of code that line points to.
If you have to use code from another class, you may need to do something like...
Dim MyWindowWhereProgressIs As New MyWindowWhereProgressIs
And then, each time you need to change the value, try...
MyWindowWhereProgressIs.MyProgressBar.Value = MyWindowWhereProgressIs.MyProgressBar.Value + 1
I'm not entirely sure whether or not those last two lines of code will work, as I'm away from Visual Studio right now, but it is worth a shot.

Resources