[QUOTE=Proclivitas;44039853]Alright; there has got to be an easier way to do what I'm doing and I just don't know about it. First the code is here, [URL="https://github.com/Proclivitas/CPP_Early_Objects_Eighth_Edition/tree/master/Chapter%20Four/Programming%20Challenges/Problem%2021"]https://github.com/Proclivitas/CPP_Early_Objects_Eighth_Edition/tree/master/Chapter%20Four/Programming%20Challenges/Problem%2021[/URL], I'm specifically talking about my switch statement at line 38 in main.cpp. As you can see, I am passing values from instances of Package class which stores information on types of phone service packages you can receive; I am then passing the the values from the instance of the Package class to a variable in my newCustomer class. I would like to assume that there is a way to pass the instance of my Package class, say PackageA, and then call Package.A.getPricePerMonth() as you see I am trying to do within customer.cpp at line 39 with by using the parameter "Package p" and then I try to call the passed package, but it won't allow me to use Package as a user defined data type because it doesn't recognize it. I then tried to include the package.h file into my customer.cpp and that just threw a whole bunch of errors.[/QUOTE]
Resolve the errors by adding include guards to your header files.
Then make the getters of Package const and pass "const Package&" to Customer.
[QUOTE=Dienes;44040167]Resolve the errors by adding include guards to your header files.
Then make the getters of Package const and pass "const Package&" to Customer.[/QUOTE]
Once again Dienes, you solve all my problems. Have my children.
Is there a way to disable these asserts? i'm using VS2013.
[QUOTE]
Debug Assertion Failed!
Program: C:\windows\system32\MSVCP110D.dll
File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector
Line: 159
Expression: vector iterator + offset out of range
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)[/QUOTE]
I know what causes them, and why it causes them. I just don't care. It works perfectly fine in Release mode and should not cause any problems.
However, i cannot debug in release mode. Which makes this a problem.
[CODE]
std::vector<Marble>::iterator emptySpace = std::find(m_Array.begin(), m_Array.end(), eEmpty);
std::vector<Marble>::iterator newLocation = emptySpace + (m_Direction*2);
if (newLocation >= m_Array.begin() && newLocation < m_Array.end())
{
if (*newLocation != *(newLocation-m_Direction))
{
return true;
}
}
return false;
[/CODE]
[QUOTE=Sergesosio;44040276]Is there a way to disable these asserts? i'm using VS2013.
I know what causes them, and why it causes them. I just don't care. It works perfectly fine in Release mode and should not cause any problems.
However, i cannot debug in release mode. Which makes this a problem.
[CODE]
std::vector<Marble>::iterator emptySpace = std::find(m_Array.begin(), m_Array.end(), eEmpty);
std::vector<Marble>::iterator newLocation = emptySpace + (m_Direction*2);
if (newLocation >= m_Array.begin() && newLocation < m_Array.end())
{
if (*newLocation != *(newLocation-m_Direction))
{
return true;
}
}
return false;
[/CODE][/QUOTE]
I'd suggest you check with std::distance() if your returned iterator has a valid distance to m_Array.end(), that way you don't push the iterator out of bounds.
I just spent the past hour trying to figure out why
[code]
overageFee = ((this->_minutesUsed - p.getMinutesAlloted) * p.getPricePerMinute);
[/code]
wasn't working. Stupid method invocation operators and misleading compiler error codes >.>
[QUOTE=Proclivitas;44040419]I just spent the past hour trying to figure out why
[code]
overageFee = ((this->_minutesUsed - p.getMinutesAlloted) * p.getPricePerMinute);
[/code]
wasn't working. Stupid method invocation operators and misleading compiler error codes >.>[/QUOTE]
What compiler are you using? At least in VS2013 I'm getting a quite precise error for that:[code]
error C3867: 'MyClass::getFoo': function call missing argument list; use '&MyClass::getFoo' to create a pointer to member
[/code]
[QUOTE=Dienes;44040453]What compiler are you using? At least in VS2013 I'm getting a quite precise error for that:[code]
error C3867: 'MyClass::getFoo': function call missing argument list; use '&MyClass::getFoo' to create a pointer to member
[/code][/QUOTE]
I'm using VS2013 as well. I just had no idea how to read what that meant and the error code didn't really reveal it to me on MSDN >.>. Just need more experience I guess.
From what I understand now, missing argument list means getFoo, and having one means getFoo(). Understood.
I want to write FP post rating retriever in C# but I got a little paranoid about the amount of http requests I can make before cloudfare or some other thing kicks in and blocks everything.
I saw security token use in the WAYWO generator but I'm not sure how it works exactly.
snip i figured it out
I decided to practice C# again by making a little game. This is the overall code so far.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Game
{
class Program
{
static void Main(string[] args)
{
string input;
createPlayer();
while(true)
{
input = Console.ReadLine();
}
}
static void createPlayer()
{
Console.Write("What is your name?: ");
Char player = new Char() { name = Console.ReadLine(), health = 100, ap = 10, isPlayer = true};
Weapon hands = new Weapon { name = "hands", weight = 0 };
player.equipped = hands;
player.info();
Weapon sword = new Weapon { name = "sword", weight = 2 };
player.give(sword);
}
}
public class Char
{
public string name;
public Weapon equipped;
public int health, ap;
public bool isPlayer;
private bool turn;
public Item[] inv = {};
public void info()
{
Console.WriteLine("Name: " + name + "\nEquipped: " + equipped.name + "\nHealth: " + health + "\nAP: " + ap + "\nInventory: ");
foreach(Item i in inv)
{
Console.WriteLine(i.name + ", " + i.weight);
}
}
public void give(Item y)
{
inv[inv.Length+1] = y;
}
private void sortInv()
{
int index = 0;
Item[] tempInv = {};
foreach (Item i in inv)
{
if (i.name != "")
tempInv[index] = inv[index];
index++;
}
inv = tempInv;
}
}
public class Item
{
public int weight;
public string name;
}
public class Weapon : Item
{
private int damage;
public int getDamage()
{
return damage;
}
}
}
[/code]
The problem I am having is with..
[code]
public void give(Item y)
{
inv[inv.Length+1] = y;
}[/code]
When it goes to place the item into the inventory I get an error saying that the index is outside the bounds of the array. Did I declare the inventory array incorrectly?
[QUOTE=JakeAM;44045268]I decided to practice C# again by making a little game. This is the overall code so far.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Game
{
class Program
{
static void Main(string[] args)
{
string input;
createPlayer();
while(true)
{
input = Console.ReadLine();
}
}
static void createPlayer()
{
Console.Write("What is your name?: ");
Char player = new Char() { name = Console.ReadLine(), health = 100, ap = 10, isPlayer = true};
Weapon hands = new Weapon { name = "hands", weight = 0 };
player.equipped = hands;
player.info();
Weapon sword = new Weapon { name = "sword", weight = 2 };
player.give(sword);
}
}
public class Char
{
public string name;
public Weapon equipped;
public int health, ap;
public bool isPlayer;
private bool turn;
public Item[] inv = {};
public void info()
{
Console.WriteLine("Name: " + name + "\nEquipped: " + equipped.name + "\nHealth: " + health + "\nAP: " + ap + "\nInventory: ");
foreach(Item i in inv)
{
Console.WriteLine(i.name + ", " + i.weight);
}
}
public void give(Item y)
{
inv[inv.Length+1] = y;
}
private void sortInv()
{
int index = 0;
Item[] tempInv = {};
foreach (Item i in inv)
{
if (i.name != "")
tempInv[index] = inv[index];
index++;
}
inv = tempInv;
}
}
public class Item
{
public int weight;
public string name;
}
public class Weapon : Item
{
private int damage;
public int getDamage()
{
return damage;
}
}
}
[/code]
The problem I am having is with..
[code]
public void give(Item y)
{
inv[inv.Length+1] = y;
}[/code]
When it goes to place the item into the inventory I get an error saying that the index is outside the bounds of the array. Did I declare the inventory array incorrectly?[/QUOTE]
Once defined, a basic array cannot expand. You define your array to be empty, so you cannot access any item at all. You probably want something like List<Item>.
Arrays have a fixed size once initialised.
Here you are declaring an empty array:
[code]public Item[] inv = {};[/code]
Therefore there are no free slots in the array to allocate values to.
This will also never work, since it will always try and access an index one higher than the maximum:
[code]inv[inv.Length+1] = y;[/code]
Either initialise your array with a fixed number of slots like so, or look into alternative data structures (I assume C# has some sort of ArrayList implementation):
[code]public Item[] inv = new Item[32];[/code]
[QUOTE=Vietnow;44045521]Arrays have a fixed size once initialised.
Here you are declaring an empty array:
[code]public Item[] inv = {};[/code]
Therefore there are no free slots in the array to allocate values to.
This will also never work, since it will always try and access an index one higher than the maximum:
[code]inv[inv.Length+1] = y;[/code]
Either initialise your array with a fixed number of slots like so, or look into alternative data structures (I assume C# has some sort of ArrayList implementation):
[code]public Item[] inv = new Item[32];[/code][/QUOTE]
Ahh ok thanks. However now it throws me the error object reference is not set to the instance of an object.
[code]
public void info()
{
Console.WriteLine("Name: " + name + "\nEquipped: " + equipped.name + "\nHealth: " + health + "\nAP: " + ap + "\nInventory: ");
foreach(Item i in inv)
{
if(i.name != "")
{
Console.WriteLine(i.name + ", " + i.weight);
}
}
}
[/code]
I would just like to know how to implement a void function (which for instance returns a string) in a C/C++ GUI program and show the output in a window.
Would you put it in a WM_CREATE case in the WndProc function or under the WinMain function? Or is it more complicated, as in, you have to redirect the Command Prompt output to the window?
So, I have, for example...
[code]void function() {
cout << "Hello";
}[/code]
and then I want to implement this in a GUI...
[cpp]LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
// Implement function somewhere here?
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
}[/cpp]
I posted this in the Game Maker discussion but I figure since it's more of a theory question rather than a Game Maker specific question, I'd ask it here too.
[quote]I'm playing around with a game at the moment, and want certain hud elements to change when certain conditions are met.
ie: Player at game start has no weapons.
No weapon icons in the HUD are active.
Player picks up and equips a shotgun.
Shotgun HUD icon is lit up, and has a border to show it's equipped.
Player then picks up a Rifle.
Rifle HUD icon is lit up and bordered, shotgun icons border is removed.
What is the best way to handle this? At the moment I've got a few variables, for whether a weapon is PICKED-UP, and whether a weapon is EQUIPPED to control these hud elements. The HUD elements are controlled with simple IF statements.
However, I feel there should be a much more efficient and less intensive way to achieve this. Would this be a case where WHILE statements would be better?
Basically, I'm asking how YOU would have these HUD elements behave.
Thanks[/quote]
[QUOTE=JakeAM;44045773]Ahh ok thanks. However now it throws me the error object reference is not set to the instance of an object.
[code]
public void info()
{
Console.WriteLine("Name: " + name + "\nEquipped: " + equipped.name + "\nHealth: " + health + "\nAP: " + ap + "\nInventory: ");
foreach(Item i in inv)
{
if(i.name != "")
{
Console.WriteLine(i.name + ", " + i.weight);
}
}
}
[/code][/QUOTE]
Use lists. They are basically dynamic arrays. You can access them with an index, so your sorting algorithm should work without a problem. But a lists grows automatically when you add items.
Also added some other suggestions :)
Try this (comments are in the code as...comments :v:)
[code]
using System.Collections.Generic;
public class Char // beter call it character to avoid confusion
{
// don't use inv :p this is not javascript, variable length doesn't cost anything and just makes it harder on yourself
public List<Item> inventory;
public Char()
{
inventory = new List<Item>();
}
// consider returning this information as a string instead of directly outputting to console
public void Info()
{
// consider using String.format, not required or so, but definitely a handy feature
Console.WriteLine(string.Format("Name: {1} {0} Equipped: {2} {0} Health: {3} {0} Inventory {4}", Environment.NewLine, name, equipped.name, health, ap));
foreach(Item i in inventory)
{
Console.WriteLien(string.Format("{0}, {1}", i.name, i.weight));
}
}
public void Give(Item i)
{
// use this if you want a limited inventory space
if(inventory.Count == 32)
{
return;
}
inv.Add(i);
}
// if you want to remove a item
public void Remove(Item i)
{
inventory.Remove(i);
}
}[/code]
Did it quickly in notepad, if the variables don't check out, use intellisense :p
Does anyone know of a more elegant way to debug programs which have multiple processes in Visual Studio?
My current method is to have the program wait for input while I go back into visual studio and manually attach the debugger to each process. I have tried [url=http://visualstudiogallery.msdn.microsoft.com/8cccc206-b9de-42ef-8f5a-160ad0f017ae]ReAttatch[/url] but it only ever lists one process.
[QUOTE=Arxae;44052283]Use lists. They are basically dynamic arrays. You can access them with an index, so your sorting algorithm should work without a problem. But a lists grows automatically when you add items.
Also added some other suggestions :)
Try this (comments are in the code as...comments :v:)
[code]
using System.Collections.Generic;
public class Char // beter call it character to avoid confusion
{
// don't use inv :p this is not javascript, variable length doesn't cost anything and just makes it harder on yourself
public List<Item> inventory;
public Char()
{
inventory = new List<Item>();
}
// consider returning this information as a string instead of directly outputting to console
public void Info()
{
// consider using String.format, not required or so, but definitely a handy feature
Console.WriteLine(string.Format("Name: {1} {0} Equipped: {2} {0} Health: {3} {0} Inventory {4}", Environment.NewLine, name, equipped.name, health, ap));
foreach(Item i in inventory)
{
Console.WriteLien(string.Format("{0}, {1}", i.name, i.weight));
}
}
public void Give(Item i)
{
// use this if you want a limited inventory space
if(inventory.Count == 32)
{
return;
}
inv.Add(i);
}
// if you want to remove a item
public void Remove(Item i)
{
inventory.Remove(i);
}
}[/code]
Did it quickly in notepad, if the variables don't check out, use intellisense :p[/QUOTE]
Thanks a lot, that's extremely handy :)
[editline]26th February 2014[/editline]
For some reason, the inventory has stopped working. The method player.give doesn't seem to work anymore... I may be just being stupid.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Game
{
class Program
{
static void Main(string[] args)
{
string input;
createPlayer();
while(true)
{
input = Console.ReadLine().ToLower();
}
}
static void createPlayer()
{
Console.Write("What is your name?: ");
Character ply = new Character { name = Console.ReadLine(), health = 100, ap = 10, turn = true };
Console.WriteLine(ply.info());
Dungeon dung = new Dungeon();
dung.fill(ply, 0, 0);
dung.map(ply);
Weapon cheese = new Weapon { name = "cheese" };
ply.give(cheese);
ply.room.look();
}
static Weapon createWeapon(string name, int damage, int ap)
{
Weapon w = new Weapon { name = name, damage = damage, ap = ap };
return w;
}
}
public class Character
{
public string name = "null";
public Weapon weapon = new Weapon { name = "hands" , damage = 1, ap = 5};
public int health = 100, ap = 10;
public Room room;
public bool turn = false;
private List<Item> inventory = new List<Item>();
public string info()
{
string info = string.Format("Name: {1} {0}Equipped: {2} {0}Health: {3} {0}AP: {4} {0}Inventory: {5}", Environment.NewLine, name, weapon.name, health, ap, inventory.Count());
foreach (Item i in inventory)
{
if (i is Item)
{
info += i.ToString() + " - " + i.name;
}
}
return info;
}
public void equip(Weapon x)
{
weapon = x;
}
public void give(Item x)
{
inventory.Add(x);
}
public void remove(Item x)
{
inventory.Remove(x);
}
public void attack(Character x)
{
if (turn)
{
if (x is Character)
{
if (ap >= weapon.ap)
{
x.health -= weapon.damage;
ap -= weapon.ap;
}
else { Console.WriteLine("Not enough AP."); }
}
else { Console.WriteLine("You can't attack that."); }
}
else { Console.WriteLine("It's not your turn."); }
}
}
public class Item
{
public string name;
public void create(string n)
{
Weapon wep = new Weapon();
wep.name = n;
}
}
public class Weapon : Item
{
public int damage;
public int ap;
}
public class Room
{
public char symbol;
public int x, y;
private List<Character> Occupants = new List<Character>();
public void genEms(Room r)
{
Random ran = new Random();
for (int i = 0; i < ran.Next(0, 5); i++ )
{
Character eny = new Character { room = r };
r.Occupants.Add(eny);
}
}
public void look()
{
Console.WriteLine(Occupants.Count());
foreach(Character c in Occupants)
{
Console.WriteLine(c.name + "with " + c.health + " health, holding ", c.weapon);
}
}
}
public class Dungeon : Room
{
public string name;
public const int size = 5;
public Room[,]rooms = new Room[size, size];
public void fill(Character ply, int startX, int startY)
{
Console.WriteLine("Filling dungeon...");
for (int y = 0; y < size; y++)
{
for (int x = 0; x < size; x++)
{
Room r = new Room { symbol = 'O' , x = x, y = y};
rooms[x, y] = r;
genEms(r);
}
}
ply.room = rooms[startX, startY];
}
public void map(Character ply)
{
for (int y = 0; y < size; y++)
{
for (int x = 0; x < size; x++)
{
if(rooms[x, y] == ply.room)
{
Console.Write("X");
}
else
{
Console.Write("O");
}
//Console.Write("[" + rooms[x, y].x + "," +rooms[x, y].y + "] ");
}
Console.Write("\n");
}
}
}
}
[/code]
[QUOTE=Kenneth;44053447]Does anyone know of a more elegant way to debug programs which have multiple processes in Visual Studio?
My current method is to have the program wait for input while I go back into visual studio and manually attach the debugger to each process. I have tried [url=http://visualstudiogallery.msdn.microsoft.com/8cccc206-b9de-42ef-8f5a-160ad0f017ae]ReAttatch[/url] but it only ever lists one process.[/QUOTE]
You tried System.Diagnostics.Debugger.Break(); ?
[quote]For some reason, the inventory has stopped working. The method player.give doesn't seem to work anymore... I may be just being stupid.[/quote]
What exactly doesn't work about it?
Also
[code]
// instead of
Character ply = new Character { name = Console.ReadLine(), health = 100, ap = 10, turn = true };
// use the constructor
public Character(string _name)
{
name = _name;
health = 100;
ap = 10;
turn = true;
}
Character ply = new Character(Console.ReadLine());
// same for the weapon
// no
Weapon cheese = new Weapon { name = "cheese" };
// yes
public class Item
{
public string name;
public Item(string _name)
{
name = _name;
}
}
public class Weapon : Item
{
public int damage;
public int ap;
// call base constructor
public Weapon(string name, int _damage, int _ap): base(name)
{
damage = _damage;
ap = _ap;
}
}
[/code]
And it's probably better the use Ply as a class level variable instead of in the createPlayer() method. The method should only create/initialize the player variable. If you continue this route, your createPlayer() method will hold your main loop.
A guess is that the inventory stops working because as soon as you exit your createPlayer() method, your player variable goes out of scope.
If you want you can add me on steam. If yes, pm me :p
So I'm sure this isn't going to be a super popular question, but I'll ask it anyways:
Does anyone know of a decent 2D library for Android's OpenGL ES? I'm not very comfortable or experienced with OpenGL, and frankly, I have no interest in getting into the nitty-gritty with it, because I have no interest in graphics beyond "I want to draw this shape on the screen" (I am more of a data-structures person). I don't want to deal with shaders or matrices or any of that if I can avoid it.
All I need is the ability to draw colored segmented lines of variable width, colored rectangles, and colored spheres. I don't even need image / sprite support necessarily.
Googling around isn't finding too much, but I thought I'd ask here, on the off-chance one of you guys knows.
Thanks in advance. :v:
Newbie programmer wondering if there is anything similar to Lua tables in c#? An object that can hold an array of any type without being restricted to a set type. If there is a way how would I go about doing this or even point me in the right direction to learn.
[QUOTE=Kidd;44069912]Newbie programmer wondering if there is anything similar to Lua tables in c#? An object that can hold an array of any type without being restricted to a set type. If there is a way how would I go about doing this or even point me in the right direction to learn.[/QUOTE]
Object arrays or lists or dictionaries.
[code]
Vegetable Potato = new Vegetable(true);
Item1 Handsome = new Item1();
Item2 Pants = new Item2();
object[] Stuff = new object[]{new Mouse(), Potato.GetCarrot(), Handsome, Pants};
Vegetable _Potato = (Vegetable)Stuff[1];
Mouse M = (Mouse)Stuff[0];
[/code]
[QUOTE=Kidd;44069912]Newbie programmer wondering if there is anything similar to Lua tables in c#? An object that can hold an array of any type without being restricted to a set type. If there is a way how would I go about doing this or even point me in the right direction to learn.[/QUOTE]
[url=http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject(v=vs.110).aspx]DynamicObject[/url]s and ExpandoObjects.
Beware, though, there's only a few cases where the approach of using dynamics in C# is really needed, such as when (de)serializing data. There is probably a lot of type casting overhead when using dynamics, so I'd advise not to use it unless where absolutely required.
I've spent the last 2 months implementing a rotationally invariant (well, multiples of Pi/2, centroids and stuff like that would take days) algorithm, and now it turns any matches up as the rotated versions of my reference block. It's almost as if it's laughing in my face...
I'd do it in CUDA but I still enjoy my life.
[QUOTE=Kidd;44069912]Newbie programmer wondering if there is anything similar to Lua tables in c#? An object that can hold an array of any type without being restricted to a set type. If there is a way how would I go about doing this or even point me in the right direction to learn.[/QUOTE]
Dictionaries or Hashmaps.
But I think Hashmaps are deprecated or not thread safe or something in C#
Edit:
They're hashtables and Dictionary is just a generic Hashtable implementation.
[QUOTE=Kidd;44069912]Newbie programmer wondering if there is anything similar to Lua tables in c#? An object that can hold an array of any type without being restricted to a set type. If there is a way how would I go about doing this or even point me in the right direction to learn.[/QUOTE]
Usually mixed collections (collection that contain different types of elements) are really not that useful.
Unless there's some kind of polymorphism going on (but in that case all elements are still inheriting from the same ancestor so you could say they're not really different).
If you really want a mixed collection the most fitting thing would be "List<object>"
You could use it like this.
List<object> myList = new List<object>();
myList.Add(5);
myList.Add("some text");
And then use its contents like this
foreach(object o in myList) Console.WriteLine(o);
or like this:
foreach(object o in myList)
if(o is int)
Console.WriteLine("the int plus one: " + ((int)o + 1));
else if(o is string)
Console.WriteLine("A string: " + o);
else
Console.WriteLine("There is a element of unknown type (" + o.GetType() + ") and it's ToString gives: " + o.ToString());
If you want a collection that contains elements of the same ancestor use "List<MyRootType>".
The first thing (with object as TypeParameter) is similar to this one in a way because in .NET all classes (and trough boxing even value types) all inherit from "System.Object"
Are there any algorithms that let me find common patterns between different strings?
For example if I have "asd123dsaSSS", "zaj123kvaSSS" and "35112303fSSS" I want to make a function to return something like "***123***SSS"
-edit-
Nevermind I'm stupid
Am I correct in saying if you have a VBO in OpenGL, and you have culling on, the VBO will still be drawn if just one vertice is visible?
I have performance issues at the moment and most of a VBO isnt even visible but im assuming its still being drawn
[editline]1st March 2014[/editline]
[QUOTE=superstepa;44085060]Are there any algorithms that let me find common patterns between different strings?
For example if I have "asd123dsaSSS", "zaj123kvaSSS" and "35112303fSSS" I want to make a function to return something like "***123***SSS"
-edit-
Nevermind I'm stupid[/QUOTE]
Im assuming you figured it out, but just incase, you could just:
[code]
String matches = "";
for(int i =0; i < min(str1.length, str2.length); i++ )
{
if( str1[i] == str2[i] )
matches += str1[i];
else
matches += "*";
}
[/code]
Im currently using [url]http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/[/url] for my movement which works fine for normal flat FPS, but im trying to make the lpayer be able to walk around a circular object, therefore forward wouldnt always be +-Z, I tried using the same code but making UP be the direction of the origin to the player as the center of the sphere is the origin, but that didnt work.
Anyone have any idea how to do it?
[QUOTE=Richy19;44093112]Im currently using [url]http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/[/url] for my movement which works fine for normal flat FPS, but im trying to make the lpayer be able to walk around a circular object, therefore forward wouldnt always be +-Z, I tried using the same code but making UP be the direction of the origin to the player as the center of the sphere is the origin, but that didnt work.
Anyone have any idea how to do it?[/QUOTE]
Not quite sure what you mean. In that example, forward and right vectors are calculated from the current player orientation. How is what you want different from that?
Sorry, you need to Log In to post a reply to this thread.