I have a Java question- if I'm getting a string such as "1. 5", is there a way to separate the "5" from the "1. " without making both halves into an array? The first number changes with each new line of input.
[QUOTE=Metherat;43339683]I have a Java question- if I'm getting a string such as "1. 5", is there a way to separate the "5" from the "1. " without making both halves into an array? The first number changes with each new line of input.[/QUOTE]
You could use something like String.substring(). You'd have to get the index of the '.' obviously, but that's not hard at all.
This is assuming you only care about getting the first half as a String by itself. Knowing what you need to do with it would help provide a better answer really.
[QUOTE=Metherat;43339683]I have a Java question- if I'm getting a string such as "1. 5", is there a way to separate the "5" from the "1. " without making both halves into an array? The first number changes with each new line of input.[/QUOTE]
Yes, but the easiest way is probably to split() after the ". " sequence and pick the parts from the resulting array. Weirdly enough that method takes a regex, so something like "(?<=\. )" should match in-between the space and the next number, if the format doesn't change at all.
[editline]29th December 2013[/editline]
If you only need certain parts, you could use a capturing regex to select them from the input line in one command.
Hey guys, I'm trying to get a road creation algorithm to work but I can't get the weighting correct. Without the weighting the roads tend to go around in circles till it freezes or runs out of memory, the excerpt I'm trying to figure out it this:
[quote]3.2.1 Population density
As mentioned above, the highways build the main connection
medium between different highly populated areas of a city
whereas streets develop into the residential areas and give the
habitants access to the next highway [12]. The determination of
the parameters of a highway segment are described as follows:
Highways connect centers of population. To find the next popu-
lation center, every highway road-end shoots a number of rays
radially within a preset radius. Along this ray, samples of the
population density are taken from the population density map.
The population at every sample point on the ray is weighted with
the inverse distance to the roadend and summed up. The direc-
tion with the largest sum is chosen for continuing the growth.
This mechanism is illustrated in figure 4[/quote]
I'm using this equation for the weighting
[code]float inverseWeight(Highway HW, Vector2 pos)
{
Vector2 end = HW.getRoadStart().Position;
//Debug.DrawRay(HW.getRoadStart().Position.Vec2ToVec3(), Vector3.up, Color.blue, 100f);
return -Mathf.Pow(end.y - HW.Position.y,2) - Mathf.Pow(end.x - HW.Position.x,2);
}[/code]
After that I get the population and times them together.
I can't get the .NET XMLSerializer to work properly. It does it's job right when serializing the structure into XML:
[code]
<?xml version="1.0" encoding="utf-8"?>
<DuckQuackConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Servers>
<Server>
<Label>Google Server</Label>
<Hostname>google.com</Hostname>
<Providers>
<PingProvider xsi:type="ICMPProvider">
<Timeout>5</Timeout>
</PingProvider>
<PingProvider xsi:type="TCPProvider">
<Timeout>5</Timeout>
<DestinationPort>80</DestinationPort>
</PingProvider>
</Providers>
</Server>
<Server>
<Label>Facepunch webserver</Label>
<Hostname>facepunch.com</Hostname>
<Providers>
<PingProvider xsi:type="ICMPProvider">
<Timeout>5</Timeout>
</PingProvider>
<PingProvider xsi:type="TCPProvider">
<Timeout>5</Timeout>
<DestinationPort>80</DestinationPort>
</PingProvider>
</Providers>
</Server>
<Server>
<Label>Khub's server without SRCDS</Label>
<Hostname>khubajsn.mitranet.cz</Hostname>
<Providers>
<PingProvider xsi:type="ICMPProvider">
<Timeout>5</Timeout>
</PingProvider>
<PingProvider xsi:type="TCPProvider">
<Timeout>5</Timeout>
<DestinationPort>27015</DestinationPort>
</PingProvider>
</Providers>
</Server>
<Server>
<Label>I don't exist</Label>
<Hostname>1.2.3.4</Hostname>
<Providers>
<PingProvider xsi:type="ICMPProvider">
<Timeout>5</Timeout>
</PingProvider>
<PingProvider xsi:type="TCPProvider">
<Timeout>5</Timeout>
<DestinationPort>1337</DestinationPort>
</PingProvider>
</Providers>
</Server>
</Servers>
<PingInterval>60</PingInterval>
<OutputFilePath>c:\output.json</OutputFilePath>
</DuckQuackConfiguration>
[/code]
Deserialization runs with no exceptions raised, but the serialized object is corrupted.
All the <PingProvider>'s appear to get collected into some virtual list that's later assigned to each of the servers. That way, every server from the XML code above has 8 PingProviders. I'm quite desperate about this, I couldn't Google any solutions. I'm willing to provide more code snippets if need be.
[t]http://i.imgur.com/T5I96m9.png[/t]
Quick question concerning imports in Python; this is my file layout as of now:
[code]
|PROJECT
|--|Elements
| |__init__.py
| |ElementA.py
|
|--|Main
| |__init__.py
| |Loader.py
[/code]
This is the __init__ file in my elements folder:
[code]
#Elements/__init__.py
import ElementA
[/code]
this is the ElementA file:
[code]
#Elements/ElementA.py
class ElementA:
def __init__(self):
self.type = "element"
[/code]
And here are a bunch of ways I've tried importing ElementA that have somehow failed me:
[code]
import Elements
Element = Elements.ElementA() #AttributeError: 'module' object has no attribute 'ElementA'
####
from Elements import *
Element = ElementA() #NameError: name 'ElementA' is not defined
####
from Elements import ElementA
Element = ElementA() #ImportError: cannot import name ElementA
####
from Elements.ElementA import *
Element = ElementA() #ImportError: cannot import name ElementA
####
from Elements.ElementA import ElementA
Element = ElementA() #ImportError: cannot import name ElementA
[/code]
How in the fuck is Python expecting me to import this? I've tried a dozen other methods too but they didn't work either. This shit is really confusing the balls out of me.
This should be really simple but it's giving me weird results. It's C# and XNA/monogame.
[code]
public void DoMovement(GameTime gameTime)
{
if (DestinationTile != null)
{
_position.X = MathUtil.Approach(_position.X, DestinationTile.Position.X, (float) (_moveTime.TotalMilliseconds / Math.Abs(_position.X - DestinationTile.Position.X)));
_position.Y = MathUtil.Approach(_position.Y, DestinationTile.Position.Y, (float) (_moveTime.TotalMilliseconds / Math.Abs(_position.Y - DestinationTile.Position.Y)));
if (_position.X == DestinationTile.Position.X && _position.Y == DestinationTile.Position.Y)
{
_gridPosition = DestinationTile.GridPosition;
if (CurTile != null)
{
CurTile.Actor = null;
}
DestinationTile.Actor = this;
CurTile = DestinationTile;
DestinationTile = null;
}
}
}
public static class MathUtil
{
public static float Approach(float cur, float dest, float increment)
{
if (cur < dest)
{
return MathHelper.Clamp(cur + increment, cur, dest);
}
else
{
return MathHelper.Clamp(cur - increment, dest, cur);
}
}
}[/code]
I'm trying to make an entity move from point A to B linearly.
_moveTime is a TimeSpan with an arbitrary amount of milliseconds... In other words i want to be able to specify how long it takes for the entity to move. So i'm dividing the distance by the amount of milliseconds but that doesn't seem right.
Pretty sure I got input error handling down. Critique?
[code]/*
---Exercise 9---
Write a program that asks the user to type an integer between 0 and 20 (both included) and writes N+17.
If someone types a wrong value, the program writes ERROR and he must type another value.
*/
#include <iostream>
using namespace std;
int main() {
int n;
for (;;) {
cout << "Please enter an integer between 0 and 20: ";
if ((cin >> n) && (!(n < 0 || n > 20))) {
break;
}
else {
cout << "ERROR" << "\n";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
}
cout << n + 17 << "\n";
return 0;
}[/code]
[code]stringVariable = "value"[/code]
Why in C# does this result in an error saying Cannot implicitly convert type 'string' to 'bool'...
[code]stringVariable != "value"[/code]
...whilst this doesn't?
[QUOTE=Rufia;43363208][code]stringVariable = "value"[/code]
Why in C# does this result in an error saying Cannot implicitly convert type 'string' to 'bool'...
[code]stringVariable != "value"[/code]
...whilst this doesn't?[/QUOTE]
[code]=[/code] is assignment only, [code]==[/code] is the comparing operator.
[editline]31st December 2013[/editline]
The assignment also "returns" the assigned value, so you can chain them or use them in brackets.
-snip-
Wish I knew someone who was good at/knows ppc... Running in circles with IDA and tons of assembly. :(
[IMG]http://i.imgur.com/vNx6YPn.png[/IMG]
(hint: if you know ppc, please add me on steam! I'll buy you any steam game 11.92 or less!)
-snip-
[QUOTE=Rob Markia;43364778]Wish I knew someone who was good at/knows ppc... Running in circles with IDA and tons of assembly. :(
[IMG]http://i.imgur.com/vNx6YPn.png[/IMG]
(hint: if you know ppc, please add me on steam! I'll buy you any steam game 11.92 or less!)[/QUOTE]
ppc ?
[QUOTE=WinCat;43366715]ppc ?[/QUOTE]
Its [B]PowerPC[/B] ASM.
He's probably reverse engineering some console stuff.
[QUOTE=Hiruty;43354059]Hey guys, I'm trying to get a road creation algorithm to work but I can't get the weighting correct. Without the weighting the roads tend to go around in circles till it freezes or runs out of memory, the excerpt I'm trying to figure out it this:
I'm using this equation for the weighting
[code]float inverseWeight(Highway HW, Vector2 pos)
{
Vector2 end = HW.getRoadStart().Position;
//Debug.DrawRay(HW.getRoadStart().Position.Vec2ToVec3(), Vector3.up, Color.blue, 100f);
return -Mathf.Pow(end.y - HW.Position.y,2) - Mathf.Pow(end.x - HW.Position.x,2);
}[/code]
After that I get the population and times them together.[/QUOTE]
I'm pretty sure that by inverse they mean 1/distance, not -distance.
[QUOTE=Anthophobian;43357905]Quick question concerning imports in Python; this is my file layout as of now:
[code]
|PROJECT
|--|Elements
| |__init__.py
| |ElementA.py
|
|--|Main
| |__init__.py
| |Loader.py
[/code]
This is the __init__ file in my elements folder:
[code]
#Elements/__init__.py
import ElementA
[/code]
this is the ElementA file:
[code]
#Elements/ElementA.py
class ElementA:
def __init__(self):
self.type = "element"
[/code]
And here are a bunch of ways I've tried importing ElementA that have somehow failed me:
[code]
--snip--
[/code]
How in the fuck is Python expecting me to import this? I've tried a dozen other methods too but they didn't work either. This shit is really confusing the balls out of me.[/QUOTE]
Have your "main" Python file in the PROJECT directory, then you can import it via [i]from Elements import ElementA[/i].
[QUOTE=NixNax123;43362332]Pretty sure I got input error handling down. Critique?
[code]/*
---Exercise 9---
Write a program that asks the user to type an integer between 0 and 20 (both included) and writes N+17.
If someone types a wrong value, the program writes ERROR and he must type another value.
*/
#include <iostream>
using namespace std;
int main() {
int n;
for (;;) {
cout << "Please enter an integer between 0 and 20: ";
if ((cin >> n) && (!(n < 0 || n > 20))) {
break;
}
else {
cout << "ERROR" << "\n";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
}
cout << n + 17 << "\n";
return 0;
}[/code][/QUOTE]
The logic is sound.
I personally would use [i]while (true)[/i] instead of [i]for (;;)[/i] and would remove the else-part, since when the condition is true it will break out of the loop and not execute any following code anyway.
[editline]31st December 2013[/editline]
[QUOTE=Rob Markia;43364778]Wish I knew someone who was good at/knows ppc... Running in circles with IDA and tons of assembly. :(
[IMG]http://i.imgur.com/vNx6YPn.png[/IMG]
(hint: if you know ppc, please add me on steam! I'll buy you any steam game 11.92 or less!)[/QUOTE]
Do you need help with something specific there or is this meant as a "if you understand this please contact me"?
[editline]31st December 2013[/editline]
[QUOTE=twoski;43359320]This should be really simple but it's giving me weird results. It's C# and XNA/monogame.
[code]
public void DoMovement(GameTime gameTime)
{
if (DestinationTile != null)
{
_position.X = MathUtil.Approach(_position.X, DestinationTile.Position.X, (float) (_moveTime.TotalMilliseconds / Math.Abs(_position.X - DestinationTile.Position.X)));
_position.Y = MathUtil.Approach(_position.Y, DestinationTile.Position.Y, (float) (_moveTime.TotalMilliseconds / Math.Abs(_position.Y - DestinationTile.Position.Y)));
if (_position.X == DestinationTile.Position.X && _position.Y == DestinationTile.Position.Y)
{
_gridPosition = DestinationTile.GridPosition;
if (CurTile != null)
{
CurTile.Actor = null;
}
DestinationTile.Actor = this;
CurTile = DestinationTile;
DestinationTile = null;
}
}
}
public static class MathUtil
{
public static float Approach(float cur, float dest, float increment)
{
if (cur < dest)
{
return MathHelper.Clamp(cur + increment, cur, dest);
}
else
{
return MathHelper.Clamp(cur - increment, dest, cur);
}
}
}[/code]
I'm trying to make an entity move from point A to B linearly.
_moveTime is a TimeSpan with an arbitrary amount of milliseconds... In other words i want to be able to specify how long it takes for the entity to move. So i'm dividing the distance by the amount of milliseconds but that doesn't seem right.[/QUOTE]
Have you tried distance / _moveTime?
And you need to store the distance in the beginning for a constant velocity, instead of using the distance left to the target; otherwise the increment will change when the distance changes.
[QUOTE=ZeekyHBomb;43367987]Do you need help with something specific there or is this meant as a "if you understand this please contact me"?.[/QUOTE]
Both.
[QUOTE=ZeekyHBomb;43367987]
The logic is sound.
I personally would use [i]while (true)[/i] instead of [i]for (;;)[/i] and would remove the else-part, since when the condition is true it will break out of the loop and not execute any following code anyway.
[/QUOTE]
Thanks! And you're right. (:
so I'm messing around with concatenation in C++ and tried to whip up what looked like a simple program -- now I'm getting errors and my brain hurts
warning: terrible code
[code]#include <iostream>
#include <cstdlib> // system() compatibility
using namespace std;
int main(){
int echonum;
string name = "ping google.com -n ";
cout << "Enter in the duration to test your internet access: ";
cin >> echonum;
string result = name + std::to_string (echonum); // wtf am I even doing
for ( int x = 0; x <= echonum; x++ ){
system ( result ); // stop soleedus
}
// exit statement shit
cin.sync();
cin.ignore();
return 0;
}[/code]
error being thrown:
[IMG]http://puu.sh/64QDX.png[/IMG]
I suspect it's an issue with my system() which is necessary for the ping command, but I guess it could also be my to_string. any help is appreciated
[QUOTE=Soleeedus;43370973]so I'm messing around with concatenation in C++ and tried to whip up what looked like a simple program -- now I'm getting errors and my brain hurts
warning: terrible code
[code]#include <iostream>
#include <cstdlib> // system() compatibility
using namespace std;
int main(){
int echonum;
string name = "ping google.com -n ";
cout << "Enter in the duration to test your internet access: ";
cin >> echonum;
string result = name + std::to_string (echonum); // wtf am I even doing
for ( int x = 0; x <= echonum; x++ ){
system ( result ); // stop soleedus
}
// exit statement shit
cin.sync();
cin.ignore();
return 0;
}[/code]
error being thrown:
[IMG]http://puu.sh/64QDX.png[/IMG]
I suspect it's an issue with my system() which is necessary for the ping command, but I guess it could also be my to_string. any help is appreciated[/QUOTE]
to_string is valid, however you need to add an include for the <string> header file to use it.
As for system, you are passing a String to something expecting a char pointer, use result.c_str().
oh wow, I don't know why I forgot to use <string>
thanks, hex
Does anyone know how to set metatables with LuaInterface/NLua? I'm trying to get metatables working on userdata so that i can use operator overloads on Vectors etc.
[QUOTE=Soleeedus;43375059]oh wow, I don't know why I forgot to use <string>
thanks, hex[/QUOTE]
To be honest, the output of the compiler isn't particularly nice in command prompt. And doesn't really explain what's missing when things are missing, so it's quite an easy thing to overlook. It's always worth referring to some online docs when it tells you something isn't part of a namespace when you know it is. Usually just a missing header or something :v:
Anyone here know how to use threads in QT? Specifically how to reuse a thread?
I can create and run a thread once, but I'l like to keep it around for reuse. Is this possible or should I be creating a new thread each time I want to run it?
EDIT: Figured it out, my thread wasn't properly quitting before I tried to start it again.
[QUOTE=Rob Markia;43369442]Both.[/QUOTE]
You didn't really name anything specific in that code. Do you not understand this output at all?
You can pretty easily find out what these instructions to by downloading a ppc assembly reference.
So looking at the first block we have
[code]sub_82EF2028: # label (like what you use in C for goto), probably a function (I'm guessing the sub_ stands for subroutine)
cmplwi cr6, r4, 0 # CoMPare Logical Word with Immediate; control register 6 = compare(register 4, 0)
bne cr6, loc_82EF203C # Branch if Not Equal; if control register 6 indicates that the last comparison yielded that the two operants were different, jump to loc_82EF203C (otherwise just step to the next instruction)[/code]
Then you see the red arrow pointing to the false-branch (r4 == 0) and the green arrow to the true-branch (r4 != 0).
Let's do these two blocks, too:
[code]li r11, 0 # Load Immediate; register 11 = 0
sth r11, 0(r3) # STore Half word; Imagine a C-like r3[0] = r11
# (so together with the previous instruction r3[0] = 0)
blr # Branch to Link Register; a C-like return statement[/code]
Note that a half word means a 16-bit value.
[code]loc_82EF203C: # just a normal label, no subroutine (this is the branch target)
addic. r8, r5, -1 # ADD Immediate Carrying; register 8 = register 5 + (-1)
# this operation sets the carry-bit (if the addition overflowed) and updates the control register 0
li r11, 0 # Load Immediate; r11 = 0
ble loc_82EF2070 # Branch if Less than or Equal; if control register 0 indicates that the last operation yielded that the first operant was smaller or equal to the second, jump to loc_82EF2070
# note that addic. set the control register 0, so the meaning is if r8 <= 0 then jump[/code]
I'm guessing that r4 and r5 and such are the parameters to the subroutine. You should look up the PowerPC calling convention for that.
You can also probably find an assembly -> C converter to make it a little easier to understand. They can sometimes also re-create loops and such instead of littering gotos ;)
Hey guys i am wondering how i can put my javascript into a .exe so i can send my friend friends this file and show off my code basicly.
[QUOTE=zondervan;43381161]Hey guys i am wondering how i can put my javascript into a .exe so i can send my friend friends this file and show off my code basicly.[/QUOTE]
You can't. Well, you might be able to but it's too much work. However, you could send them the JS file and have them run it in their web browser. I noticed in your other thread you were using "Console" to print things. You'd have to change some things, but then it can use a simple HTML page.
Work on it a bit more before you show people what you've done :v: Unless they know what you are sending well, sending things that require a lot of work to run makes people think you're fucking with them.
this code works fine but I don't understand it. I'm learning from a c++ programming book.
[code]while ( i < vec.size() ) {
i++ ;
vec[ i-1 ] = i ;
cout << " | " << vec.at( i-1 ) ; [/code]
this part specifically
[code] vec[ i-1 ] = i ;
cout << " | " << vec.at( i-1 ) ;[/code]
It works but I want to understand it. What am I doing by typing vec[ i-1 ] = i ; ?
removing vec[ -1 ] all together and just changing it to
[code] i++ ;
cout << " | " << i ; [/code]
[editline]2nd January 2014[/editline]
I have a tons of noob questions about c++ that I come across often while learning c++. If anyone wants to be asked questions every now any then all the time all the time then please add me.
[url]http://steamcommunity.com/id/EdBiew/[/url]
The []-operator, also called subscript operator, is overloaded for std::vector and it more or less does the same as std::vector::at.
There is a small difference: When you use [] with an invalid index, behavior is undefined, at throws an exception.
Anyone here have any experience with AutoHotkey?
Some background info to my problem: Where I'm working (it's more like volunteer work for the town but I get paid to do it), I've been asked to do some data entry since I'm "good with computers." The place I'm working at is switching their database of clients over from some weird-ass homemade program from the nineties that's really buggy and non-intuitive to a web client. The web client they're switching to isn't finished, and there's a problem where when you edit an entry it duplicates it, and they guy says it's going to take a while to fix, but in the meantime I can just put some new data into an empty field that was never used before in the old client and he'll just make it so when the new program populates the data it'll correct for that.
Here's the problem: it's a shitload of tedious data entry that will take forever, and I know I can speed this up and get it done really fast, so I thought I'd give AutoHotkey a try. What I need to do is get the email addresses from an excel file and put them into the new program, but it's a really old program so I can't just import the data, and there's other quirks that are making this harder.
Here's what I want to do:
[CODE]Loop:
Activate excel document.
Get the next person's last name from excel document. (Click on a cell, double click on formula bar, copy)
Activate Database Program.
Hold backspace to clear any text typed in before the parsing since can't highlight and delete, 4 seconds should be enough.
Type in last name that was copied from excel
[B](cannot paste it, though, so have to parse each individual letter into a keypress {this is where I'm stuck!}), [/B]
Double click on first result that should always be in a specific spot.
Click on a specific spot.
Activate Excel document again.
Copy email address from cell next to the person's last name (click on last name, press right, double click on formula bar, copy, then click back on last name, press down, click on down arrow bar to move excel screen to make next last name at top)
Activate Database program
Click on another spot
Paste in text.
Click on another spot
Repeat.
End when empty string copied at any point.[/CODE]
[B]I can do basically everything except parsing the last name string and getting a letter, typing it, parsing the next letter, typing it, and repeating until the name ends.[/B] That's what I need help with. I haven't done any coding since a java class in highschool, and that was very basic stuff. I know I probably need an array and some way to split this stuff into substrings, but I'm at a loss at what to do.
At worst, I could just do this manually, but I'd rather get it done quick so I can get back to doing my regular stuff at my job. Any help would be greatly appreciated. You don't have to write the whole code, just help with that one spot I'm stuck on would be nice or at least giving me some clues on how to do that would be appreciated.
Sorry, you need to Log In to post a reply to this thread.