Search Results

Search found 12044 results on 482 pages for 'foreach loop'.

Page 1/482 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Foreach PHP Error

    - by Logan
    I am receiving the following foreach error on my PHP file and I have no idea how to fix it. Does anyone have any ideas? When I load the page I get this: Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 61 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/merge/class/global_functions.php on line 89 Line 61 and 89 of my /class/global_functions.php are as followed: Here is my code from line 61 to line 98: foreach($GLOBALS['userpermbit'] as $v) { if(strstr($v['perm'],'|'.$pageperm_id[0]['id'].'|')) return true; } //if they dont have perms and we're not externally including functions return false if ($GLOBALS['external'] != true) return false; return true; } //FUNCTION: quick perm check using perm info from the onload perm check function stealthPermCheck($req) { #if theyre an admin give them perms if(@in_array($GLOBALS['user'][0]['id'], $GLOBALS['superAdmins'])) return true; if(!is_numeric($req)) { #if the req is numeric we need to match a title, not a permid. So try to do that foreach($GLOBALS['userpermbit'] as $v) { if(stristr($v['title'],$req)) return true; } }else{ #check if they have perms numerically if so return true foreach($GLOBALS['userpermbit'] as $v) { if(strstr($v['perm'],'|'.$req.'|')) return true; } } #if none of this returned true they dont have perms, return false return false; }

    Read the article

  • Help with converting foreach loop to while loop in c#

    - by James Dawson
    I had learnt by reading your great answers here, that it is not good practice deleting items from within a foreach loop, as it is (and I quote) "Sawing off the branch you're sitting on". My code currently removes the text from the dropdownlist, but the actual item remains (just without text displayed). In other words, it isn't deleting, and probably can't because you can't delete from within a foreach loop. After hours of trying I am unable to get my head around a way of doing it. //For each checked box, run the delete code for (int i = 0; i < this.organizeFav.CheckedItems.Count; i++) { //this is the foreach loop foreach (ToolStripItem mItem in favoritesToolStripMenuItem.DropDownItems) { //This rules out seperators if (mItem is ToolStripMenuItem) { ToolStripMenuItem menuItem = mItem as ToolStripMenuItem; //This matches the dropdownitems text to the CheckedItems String if (((ToolStripMenuItem)mItem).Text.ToString() == organizeFav.CheckedItems[i].ToString()) { //And deletes the item menuItem.DropDownItems.Remove(mItem); } } } } But it isn't deleting because it is within a foreach loop! I would greatly appreciate your help, and be truly amazed if anyone can get their head around this code :) Kind Regards

    Read the article

  • Can I pull the next element from within a Perl foreach loop?

    - by Thilo
    Can I do something like the following in Perl? foreach (@tokens) { if (/foo/){ # simple case, I can act on the current token alone # do something next; } if (/bar/) { # now I need the next token, too # I want to read/consume it, advancing the iterator, so that # the next loop iteration will not also see it my $nextToken = ..... # do something next; } }

    Read the article

  • PHP - Foreach in a foreach + CodeIgniter

    - by Sebhael
    I got an image upload function working, but there's 4 images required in this image. And my current function is simply just overwriting the image despite the number. I'm wondering how I would insert (preferably) a letter into my foreach function. $uploads = array($this->uploads->data()); foreach ( $uploads as $key[] => $value ) { $imagename = $cleaned . '-s' . $value['file_ext']; //outputs clean-name-s.ext } By the time all is said and done, 4 images will require this function. Leaving me with clean-name-sa.ext, clean-name-sb.ext, clean-name-sc.ext, and clean-name-sd.ext (numbers work as well). The form does require that all 4 fields are filled out before submission, so would I just create an array of my desired identifiers and create a foreach loop that outputs 4 different $imagenames? Or is there a simpler, more logical approach to this.

    Read the article

  • PHP foreach loop through multidimensional array

    - by Muiter
    I have an multidimensional array, how can I use it? I want to use each seperate array in an for loop. I have this code <?php foreach ($calculatie_id[$i] as $value) { echo $value; } ? print_r($calculatie_id); gives Array ( [0] = Array ( [0] = 4 [1] = 6 ) [1] = Array ( [0] = 1 [1] = 5 ) [2] = Array ( [0] = 5 [1] = 6 ) [3] = ) But when using the foreach I only get 46

    Read the article

  • Label in PyQt4 GUI not updating with every loop of FOR loop

    - by user297920
    I'm having a problem, where I wish to run several command line functions from a python program using a GUI. I don't know if my problem is specific to PyQt4 or if it has to do with my bad use of python code. What I wish to do is have a label on my GUI change its text value to inform the user which command is being executed. My problem however, arises when I run several commands using a for loop. I would like the label to update itself with every loop, however, the program is not updating the GUI label with every loop, instead, it only updates itself once the entire loop is completed, and displays only the last command that was executed. I am using PyQt4 for my GUI environment. And I have established that the text variable for the label is indeed being updated with every loop, but, it is not actually showing up visually in the GUI. Is there a way for me to force the label to update itself? I have tried the update() and repaint() methods within the loop, but they don't make any difference. I would really appreciate any help. Thank you. Ronny. Here is the code I am using: # -*- coding: utf-8 -*- import sys, os from PyQt4 import QtGui, QtCore Gui = QtGui Core = QtCore # ================================================== CREATE WINDOW OBJECT CLASS class Win(Gui.QWidget): def __init__(self, parent = None): Gui.QWidget.__init__(self, parent) # --------------------------------------------------- SETUP PLAY BUTTON self.but1 = Gui.QPushButton("Run Commands",self) self.but1.setGeometry(10,10, 200, 100) # -------------------------------------------------------- SETUP LABELS self.label1 = Gui.QLabel("No Commands running", self) self.label1.move(10, 120) # ------------------------------------------------------- SETUP ACTIONS self.connect(self.but1, Core.SIGNAL("clicked()"), runCommands) # ======================================================= RUN COMMAND FUNCTION def runCommands(): for i in commands: win.label1.setText(i) # Make label display the command being run print win.label1.text() # This shows that the value is actually # changing with every loop, but its just not # being reflected in the GUI label os.system(i) # ======================================================================== MAIN # ------------------------------------------------------ THE TERMINAL COMMANDS com1 = "espeak 'senntence 1'" com2 = "espeak 'senntence 2'" com3 = "espeak 'senntence 3'" com4 = "espeak 'senntence 4'" com5 = "espeak 'senntence 5'" commands = (com1, com2, com3, com4, com5) # --------------------------------------------------- SETUP THE GUI ENVIRONMENT app = Gui.QApplication(sys.argv) win = Win() win.show() sys.exit(app.exec_())

    Read the article

  • ForEach loop: Output something different on every second result

    - by Wade D Ouellet
    I have two for each loops and I am trying to output something different for each second result: foreach ($wppost as $wp) { $wp_title = $wp->post_title; $wp_date = strtotime($wp->post_date); $wp_slug = $wp->post_name; $wp_id = $wp->ID; // Start Permalink Template $wp_showurl = $wp_url; $wp_showurl = str_replace("%year%", date('Y', $wp_date), $wp_showurl); $wp_showurl = str_replace("%monthnum%", date('m', $wp_date), $wp_showurl); $wp_showurl = str_replace("%day%", date('d', $wp_date), $wp_showurl); $wp_showurl = str_replace("%hour%", date('H', $wp_date), $wp_showurl); $wp_showurl = str_replace("%minute%", date('i', $wp_date), $wp_showurl); $wp_showurl = str_replace("%second%", date('s', $wp_date), $wp_showurl); $wp_showurl = str_replace("%postname%", $wp_slug, $wp_showurl); $wp_showurl = str_replace("%post_id%", $wp_id, $wp_showurl); // Stop Permalink Template $wp_posturl = $blog_address . $wp_showurl; echo '<li><a href="'.$wp_posturl.'" title="'.$wp_title.'">'.$wp_title.'</a></li>'; } For this one I want it to echo li class="even" instead of just li for each second result. I think this will have to be changed to a for loop to accomplished this but I am not sure how that is done without breaking it. Exact same for this one: if(is_array($commenters)) { foreach ($commenters as $k) { ?><li><?php if($ns_options["make_links"] == 1) { $url = ns_get_user_url($k->poster_id); if(trim($url) != '') { echo "<a href='" . $url . "'>"; } } if($ns_options["make_links"] == 2) { $url = ns_get_user_profile($k->poster_id); echo "<a href='" . $url . "'>"; } $name = $bbdb->get_var(" SELECT user_login FROM $bbdb->users WHERE ID = $k->poster_id"); echo ns_substr_ellipse($name, $ns_options["name_limit"]); if(trim($url) != '' && $ns_options["make_links"] == 1) { echo "</a>"; } if($ns_options["make_links"] == 2) { echo "</a>"; } if ($ns_options["show_posts"] == 1) { echo " (" . $k->num_posts . ")\n"; } echo $ns_options["end_html"] . "\n"; unset($url); } } else { ?></li><?php } Thanks, Wade

    Read the article

  • How does this game loop actually work?

    - by Nicolai
    I read this playfulJS post, about ray-casting: http://www.playfuljs.com/a-first-person-engine-in-265-lines/ It looks really interested, so I decided to look at his javascript. I am no expert in javascript, so I quickly got lost. It's the game loop "object" that really gets me. I simply don't understand how it works. From the code: function GameLoop() { this.frame = this.frame.bind(this); this.lastTime = 0; this.callback = function() {}; } GameLoop.prototype.start = function(callback) { this.callback = callback; requestAnimationFrame(this.frame); }; GameLoop.prototype.frame = function(time) { var seconds = (time - this.lastTime) / 1000; this.lastTime = time; if (seconds < 0.2) this.callback(seconds); requestAnimationFrame(this.frame); }; var loop = new GameLoop(); loop.start(function frame(seconds) { map.update(seconds); player.update(controls.states, map, seconds); camera.render(player, map); }); Now, what really confuses me here, is this bind stuff and how this actually loops. I am guessing, that if less than 0.2 seconds have passed, since the last time the loop was run, it simply goes back to re-check the time. If more than 0.2 seconds have passed, it leaves the frame function, and executes the 3 lines in the loop. But, if this is true, then how does the loop.start() get called again? And what on earth is the meaning of this.frame = this.frame.bind(this);? I've looked up prototypes bind() but I really don't understand it.

    Read the article

  • In Perl, is a while loop generally faster than a for loop?

    - by Mike
    I've done a small experiment as will be shown below and it looks like that a while loop is faster than a for loop in Perl. But since the experiment was rather crude, and the subject might be a lot more complicated than it seems, I'd like to hear what you have to say about this. Thanks as always for any comments/suggestions :) In the following two small scripts, I've tried while and for loops separately to calcaulte the factorial of 100,000. The one that has the while loop took 57 minutes 17 seconds to finish while the for loop equivalent took 1 hour 7 minutes 54 seconds. Script that has while loop: use strict; use warnings; use bigint; my $now = time; my $n =shift; my $s=1; while(1){ $s *=$n; $n--; last if $n==2; } print $s*$n; $now = time - $now; printf("\n\nTotal running time: %02d:%02d:%02d\n\n", int($now / 3600), int(($now % 3600) / 60), int($now % 60)); Script that has for loop: use strict; use warnings; use bigint; my $now = time; my $n =shift; my $s=1; for (my $i=2; $i<=$n;$i++) { $s = $s*$i; } print $s; $now = time - $now; printf("\n\nTotal running time: %02d:%02d:%02d\n\n", int($now / 3600), int(($now % 3600) / 60), int($now % 60));

    Read the article

  • breaking out of for loop when running a function inside a for loop

    - by andrewj
    I'm embarrassed that I'm asking this question, but here I go: Suppose you have the following function foo. When I'm running a for loop, I'd like it to skip the remainder of foo when foo initially returns the value of 0. However, break doesn't work when it's inside a function. As it's currently written, I get an error message, no loop to break from, jumping to top level. Any suggestions? foo <- function(x) { y <- x-2 if (y==0) {break} # how do I tell the for loop to skip this z <- y + 100 z } for (i in 1:3) { print(foo(i)) }

    Read the article

  • breaking out of for loop when running a function inside a for loop in R

    - by andrewj
    I'm embarrassed that I'm asking this question, but here I go: Suppose you have the following function foo. When I'm running a for loop, I'd like it to skip the remainder of foo when foo initially returns the value of 0. However, break doesn't work when it's inside a function. As it's currently written, I get an error message, no loop to break from, jumping to top level. Any suggestions? foo <- function(x) { y <- x-2 if (y==0) {break} # how do I tell the for loop to skip this z <- y + 100 z } for (i in 1:3) { print(foo(i)) }

    Read the article

  • Need to convert this for loop to a while loop

    - by Bragaadeesh
    Hi guys, I solved a problem recently. But I have this one piece of code where I dont utilize the for loop initialization and condition check. It looks a bit odd that way for a for loop. I want to convert it into a while loop. Please help me do it. I tried many times, but somewhere something is missing. for(;;current =(current+1)%n){ if(eliminated[current%n]){ continue; }else{ inkiPinki++; if(inkiPinki == m){ eliminated[current%n] = true; printStatus(eliminated, people); remainingGuys--; break; } } } In the above code eliminiated[index] is a boolean.

    Read the article

  • PHP - Loop thru recordset and fire event each n rows

    - by Luciano
    I'm looking for the right logic to loop thru a recordset and fire an event each n times. Searching on Google i've found some discussion on similar situations, but it seems that solutions don't fits my needs. Let's say i have a recordset of 22 rows. I want to loop thru each row and launch a function on the 4th, the 8th, the 12th and so on... Using the modulus operator as shown in this answer, if($i % 4 == 0), i get the event fired each 4 rows, but 22 its not a multiple of 4 so the event is fired till the 20th row and then nothing. Maybe i need to make a division counting rows in 'excess'? Since the recordset will be between 50 and 200 rows i think its not necessary run multiple query of 4 rows, am I wrong? Thanks in advance!

    Read the article

  • for loop will not loop

    - by Bjørn Jostein Aurheim
    I have a for loop that I will use to compute time intervals to add to an ArrayList. The problem is that I can not prove that the for loop is being executed. Nothing is printed when using the system.out.println() statement, and nothing is added to the array from inside the loop ... any sugestions? // lager tidspunkter og legger disse inn i en Array kalt tider tid.setTimer(16); tid.setMinutter(0); tid.setSekunder(0); tider.add(tid.asString());// String "16:00" is added as it should System.out.println("tiden er: "+tid.asString());// gives 16:00 printed for(int i=0;i>12;i++){ System.out.println("er i løkken");// gives nothing printed tid.increaseMinutter(30); System.out.println(tid.asString());// gives nothing printed tider.add(tid.asString()); }

    Read the article

  • Rewriting .each() loop as for loop to optimize, how to replicate $(this).attr()

    - by John B
    I running into some performance issues with a jquery script i wrote when running in ie so I'm going through it trying to optimize any way possible. Apparently using for loops is way faster than using the jQuery .each method. This has led me to a question regarding the equivalent of $(this) inside a for loop. I'm simplifying what I'm doing in my loop down to just using an attr() function as it gets across my main underlying question. Im doing this with each(simplified) var existing = $('#existing'); existing.each(function(){ console.log($(this).attr('id')); }); And I've tried rewriting it as a for loop as such: var existing = $('#existing'); for(var i = 0;i < existing.length;i++) { console.log(existing[i].attr('id')); } Its throwing an error saying: Uncaught TypeError: Object #<HTMLDivElement> has no method 'attr' Thanks.

    Read the article

  • Limiting game loop to exactly 60 tics per second (Android / Java)

    - by user22241
    So I'm having terrible problems with stuttering sprites. My rendering and logic takes less than a game tic (16.6667ms) However, although my game loop runs most of the time at 60 ticks per second, it sometimes goes up to 61 - when this happens, the sprites stutter. Currently, my variables used are: //Game updates per second final int ticksPerSecond = 60; //Amount of time each update should take final int skipTicks = (1000 / ticksPerSecond); This is my current game loop @Override public void onDrawFrame(GL10 gl) { // TODO Auto-generated method stub //This method will run continuously //You should call both 'render' and 'update' methods from here //Set curTime initial value if '0' //Set/Re-set loop back to 0 to start counting again loops=0; while(System.currentTimeMillis() > nextGameTick && loops < maxFrameskip){ SceneManager.getInstance().getCurrentScene().updateLogic(); //Time correction to compensate for the missing .6667ms when using int values nextGameTick+=skipTicks; timeCorrection += (1000d/ticksPerSecond) % 1; nextGameTick+=timeCorrection; timeCorrection %=1; //Increase loops loops++; } render(); } I realise that my skipTicks is an int and therefore will come out as 16 rather that 16.6667 However, I tried changing it (and ticksPerSecond) to Longs but got the same problem). I also tried to change the timer used to Nanotime and skiptics to 1000000000/ticksPerSecond, but everything just ran at about 300 ticks per seconds. All I'm attempting to do is to limit my game loop to 60 - what is the best way to guarantee that my game updates never happen at more than 60 times a second? Please note, I do realise that very very old devices might not be able to handle 60 although I really don't expect this to happen - I've tested it on the lowest device I have and it easily achieves 60 tics. So I'm not worried about a device not being able to handle the 60 ticks per second, but rather need to limit it - any help would be appreciated.

    Read the article

  • Turn-based Strategy Loop

    - by Djentleman
    I'm working on a strategy game. It's turn-based and card-based (think Dominion-style), done in a client, with eventual AI in the works. I've already implemented almost all of the game logic (methods for calculations and suchlike) and I'm starting to work on the actual game loop. What is the "best" way to implement a game loop in such a game? Should I use a simple "while gameActive" loop that keeps running until gameActive is False, with sections that wait for player input? Or should it be managed through the UI with player actions determining what happens and when? Any help is appreciated. I'm doing it in Python (for now at least) to get my Python skills up a bit, although the language shouldn't matter for this question.

    Read the article

  • How to add more /dev/loop* devices on Fedora 19

    - by user219372
    How to add more /dev/loop* devices on Fedora 19? I do: # uname -r 3.11.2-201.fc19.x86_64 # lsmod |grep loop # ls /dev/loop* /dev/loop0 /dev/loop1 /dev/loop2 /dev/loop3 /dev/loop4 /dev/loop5 /dev/loop6 /dev/loop7 /dev/loop-control # modprobe loop max_loop=128 # ls /dev/loop* /dev/loop0 /dev/loop1 /dev/loop2 /dev/loop3 /dev/loop4 /dev/loop5 /dev/loop6 /dev/loop7 /dev/loop-control So nothing changes.

    Read the article

  • Trying to create an infinite for loop that can stop using function doIt()

    - by JoeOzz
    Hey guys, I'm new to javascript and I'm doing a project for my final in class. I need to make it so this game engine I manipulated causes the generation button to go for an infinite loop. I also need to stop it using (Reset==1). Any help? Here's the code I have so far if that helps: function generation() { for(y2=0; y2<2500; y2++) { tempmapactual[y2]=mapactual[y2]; } for (g=0;g<2500;g++) { neighbours=0; for (h=0;h<8;h++) { if (g+coords[h]>0 && g+coords[h]<2499 && mapactual[g+coords[h]]=="white.gif") {neighbours=neighbours+1;} } if (neighbours>=4 || neighbours==1 || neighbours==0) {tempmapactual[g]="black.gif";} if (neighbours==3) {tempmapactual[g]="white.gif";} } for(y3=0; y3<2500; ++y3) { if (mapactual[y3]!=tempmapactual[y3]) { mapactual[y3]=tempmapactual[y3]; document.images[y3+offset].src=mapactual[y3]; } } } </script> <script> function doIt() { for (i=0; i<X; i++) { // This is where I have trouble. What part of generation() do I call? } if (Reset==1) break; // This will kill the loop instantly. } } </script> <script> window.onload(doIt($(X).value))); </script> <form> <input type="button" value="generate" onClick="generation();"> </form> <form> <input type="text"> </form> <form> <input type="button" value="Infinite Loop!" onclick="doIt();"> </form> <form> <input type="button" value="Reset" onclick="doIt();"> </form>

    Read the article

  • C# - foreach showing strange behavior / for working with no problem

    - by Marks
    Hi there. Today I coded a function that uses two nested foreach loops. After seeing, that it did not work like expected, i debugged it. But I dont see an error, and dont think a simple error can cause the behavior i have noticed. The part looks like this: foreach(MyClass cItem in checkedListBoxItemList.Items) { foreach(MyClass cActiveItem in ActiveItemList) { if (cActiveItem.ID == cItem.ID) /*...check checkbox for item...*/; } } Lets say, checkedListBoxItemList.items holds 4 items of type MyClass, and ActiveItemList is a List< MyClass with 2 Items. The debugger jumps into the outer foreach, reaches inner foreach, executes the if 2 times (once per cActiveItem) and reaches the end of the outer foreach.Now, the debugger jumps back to the head of the outer foreach as it should. But instead of starting the second round of the outer foreach, the debugger suddenly jumps into the MyClass.ToString() method. I can step through this method 4 times (number of items in checkedListBoxItemList.Items) and then ... nothing. Visual Studio shows me my windows form, and the foreach is not continued. When changing the code to int ListCount = checkedListBoxItemList.Items.Count; for(int i=0; i<ListCount; i++) { MyClass cItem = checkedListBoxItemList.Items[i] as MyClass; foreach(MyClass cActiveItem in ActiveItemList) { if (cActiveItem.ID == cItem.ID) /*...check checkbox for item...*/; } } everything works fine and as supposed. I showed the problem to a collegue, but he also didnt understand, what happened. I dont understand why the debugger jumps into the MyClass.ToString() method. I used F10 to step through, so no need to leave the function. And even, if there is a reason, why isnt the foreach loop continued? Im using Visual Studio 2010, if this is of any matter. Please tell me what happened. Thanks.

    Read the article

  • How to make this game loop deterministic

    - by Lanaru
    I am using the following game loop for my pacman clone: long prevTime = System.currentTimeMillis(); while (running) { long curTime = System.currentTimeMillis(); float frameTime = (curTime - prevTime) / 1000f; prevTime = curTime; while (frameTime > 0.0f) { final float deltaTime = Math.min(frameTime, TIME_STEP); update(deltaTime); frameTime -= deltaTime; } repaint(); } The thing is, I don't always get the same ghost movement every time I run the game (their logic is deterministic), so it must be the game loop. I imagine it's due to the final float deltaTime = Math.min(frameTime, TIME_STEP); line. What's the best way of modifying this to perform the exact same way every time I run it? Also, any further improvements I can make?

    Read the article

  • C# 4.0 'dynamic' and foreach statement

    - by ControlFlow
    Not long time before I've discovered, that new dynamic keyword doesn't work well with the C#'s foreach statement: using System; sealed class Foo { public struct FooEnumerator { int value; public bool MoveNext() { return true; } public int Current { get { return value++; } } } public FooEnumerator GetEnumerator() { return new FooEnumerator(); } static void Main() { foreach (int x in new Foo()) { Console.WriteLine(x); if (x >= 100) break; } foreach (int x in (dynamic)new Foo()) { // :) Console.WriteLine(x); if (x >= 100) break; } } } I've expected that iterating over the dynamic variable should work completely as if the type of collection variable is known at compile time. I've discovered that the second loop actually is looked like this when is compiled: foreach (object x in (IEnumerable) /* dynamic cast */ (object) new Foo()) { ... } and every access to the x variable results with the dynamic lookup/cast so C# ignores that I've specify the correct x's type in the foreach statement - that was a bit surprising for me... And also, C# compiler completely ignores that collection from dynamically typed variable may implements IEnumerable<T> interface! The full foreach statement behavior is described in the C# 4.0 specification 8.8.4 The foreach statement article. But... It's perfectly possible to implement the same behavior at runtime! It's possible to add an extra CSharpBinderFlags.ForEachCast flag, correct the emmited code to looks like: foreach (int x in (IEnumerable<int>) /* dynamic cast with the CSharpBinderFlags.ForEachCast flag */ (object) new Foo()) { ... } And add some extra logic to CSharpConvertBinder: Wrap IEnumerable collections and IEnumerator's to IEnumerable<T>/IEnumerator<T>. Wrap collections doesn't implementing Ienumerable<T>/IEnumerator<T> to implement this interfaces. So today foreach statement iterates over dynamic completely different from iterating over statically known collection variable and completely ignores the type information, specified by user. All that results with the different iteration behavior (IEnumarble<T>-implementing collections is being iterated as only IEnumerable-implementing) and more than 150x slowdown when iterating over dynamic. Simple fix will results a much better performance: foreach (int x in (IEnumerable<int>) dynamicVariable) { But why I should write code like this? It's very nicely to see that sometimes C# 4.0 dynamic works completely the same if the type will be known at compile-time, but it's very sadly to see that dynamic works completely different where IT CAN works the same as statically typed code. So my question is: why foreach over dynamic works different from foreach over anything else?

    Read the article

  • PHP: Loop or no loop?

    - by Joseph Robidoux
    In this situation, is it better to use a loop or not? echo "0"; echo "1"; echo "2"; echo "3"; echo "4"; echo "5"; echo "6"; echo "7"; echo "8"; echo "9"; echo "10"; echo "11"; echo "12"; echo "13"; or $number = 0; while ($number != 13) { echo $number; $number = $number + 1; }

    Read the article

  • Walk/loop through an XSL key: how?

    - by krisvandenbergh
    Is there a way to walk-through a key and output all the values it contains? I though of it this way: <xsl:for-each select="key('kElement', '.')"> <li><xsl:value-of select="." /></li> </xsl:for-each> However, this does not work. I simply want to list all the values in a key for testing purposes. The question is simply: how can this be done?

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >